On Tuesday 14 March 2006 16:20, John Hendrikx wrote:
> I'm building my first Tapestry Component and I'm trying to encapsulate
> some common HTML components for my applications into a Tapestry
> Component.  The component also needs a few styles to look and function
> properly, and I'd like these styles to be included on the page whenever
> the component is used automatically (just like the javascript which is
> included automatically when I use my component).

I am not sure I understand precisely what you are looking for.  I have a 
border component which I am using to create the look and feel of my site, 
including a menu bar etc at the top.  I want to include the urls to two 
staticly served css files (ie with URLs outside the application url space).  
I do the following

1) Package it inside a library - so that the html template, the java code and 
a properties file are all together.

2) Call the shell component inside the borders template thus:-

<html jwcid="@Shell" title="ognl:appTitle" delegate="ognl:siteCSS" 
        doctype='html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";'>

There are two things of interest.  a) the use of non default doctype so that 
IE does not enter quirks mode, and b) the use of the delegate parameter to 
provide an inside the <head> section rendering.

3) getSiteCSS returns and IRender

        public IRender getSiteCSS(){
                return new siteCSS();
        }

4) The IRender is implemented as shown below.  the libMessage method returns 
the message for the given key from the library message bundle, appMessage 
does the same thing from the application

        private class siteCSS implements IRender {
                public void render(IMarkupWriter writer, IRequestCycle cycle) {
                        /*
                         * CSS from the library properties file - designed for 
complete site
                         */
                        writer.beginEmpty("link");
                        writer.attribute("rel","stylesheet");
                        writer.attribute("type","text/css");
                        writer.attribute("href",libMessage("cssURL"));
                        writer.println();
                        /*
                         * CSS from application (or page) properties file - 
designed for the 
application
                         */
                        writer.beginEmpty("link");
                        writer.attribute("rel","stylesheet");
                        writer.attribute("type","text/css");
                        writer.attribute("href",appMessage("cssURL"));
                        writer.println();
                        
                }
        }
        
5) I have a Border.properties file in the library with the following

cssURL=/style/site.css


6) Each application has a similar entry to 5) in the application.properties 
file to provide application specific styles.

7) In each application template I call the border something like the following

<span jwcid="@akc:Border" selectedApp="blog" appMenu="message:preview-items" 
selectedPage="article" >

(The other parameters you see are how I define the menus)


-- 
Alan Chandler
http://www.chandlerfamily.org.uk
Open Source. It's the difference between trust and antitrust.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to