We are using an excellent page designer who is doing all layout with css.

She has two "default" stylesheets that are used on every page plus
each page has a context specific stylesheet.

ie. every page includes 'template.css' and 'tags.css' and say, all
student pages use a 'student.css'

In our case we want each page to specify all the stylesheets (incl the
defaults) that are applicable to that page.

I have made a border component that contains a Shell. All stylesheets
in the system (6) are declared as named assets in the Border
component.

in Border.jwc...

<property-specification name="styleSheets"
        type="org.apache.tapestry.IAsset[]"/>

<component id="shell" type="Shell">
        ...
        <binding name="stylesheets" expression="styleSheets"/>
        ...
    </component>

 <context-asset name="templatecss" path="/css/template.css"/>
    <context-asset name="tagcss" path="/css/tag.css"/>
    <context-asset name="loginoutcss" path="/css/loginout.css"/>
    <context-asset name="studentcss" path="/css/student.css"/>
    <context-asset name="testcss" path="/css/test.css"/>
    <context-asset name="parentcss" path="/css/parent.css"/>

and in Border.java:

/**
         * Prevent the Shell component from throwing NPE for missing stylesheet 
asset
         */
        private static final IAsset NULL_ASSET = new IAsset() {

                public String buildURL(IRequestCycle cycle) {
                        return "";
                }

                .....
        };

public abstract void setStyleSheets(IAsset[] stylesheets);
public abstract IAsset[] getStyleSheets();

public void pageBeginRender(PageEvent event) {
                if (getStyleSheets() == null) {
                        
                        computeStylesheets();
                }
        }

private void computeStylesheets() {
                IPage page = getPage();
                String sheetnames = 
page.getSpecification().getProperty("stylesheets");         

                if (sheetnames == null) {
                        LOG.warn("no stylesheets found for page:" + 
page.getPageName());
                        setStyleSheets(null);
                        return;
                }

                StringTokenizer tok = new StringTokenizer(sheetnames, ",");
                int tokenCount = tok.countTokens();

                IAsset[] sheets = new IAsset[tokenCount];
                if (sheets.length == 0) {
                        LOG.warn("could not parse 'stylesheets' property:'" + 
sheetnames
                                        + "' for page:" + page.getPageName());
                        setStyleSheets(null);
                        return;
                }
                for (int i = 0; i < tokenCount; i++) {
                        String name = tok.nextToken();
                        sheets[i] = getAsset(name);
                        if (sheets[i] == null) {
                                sheets[i] = NULL_ASSET;
                                LOG
                                                .warn("missing stylesheet: '"
                                                                + name
                                                                + "'. No 
corresponding asset found in Border component.");
                        }
                }
                setStyleSheets(sheets);
        }

and on each page we have property that tells the Border which
stylesheet assets are needed for that page: (from WelcomeParent.page)

<property name="stylesheets">
        templatecss,tagcss,parentcss
    </property>



On 7/21/05, Kevin Menard <[EMAIL PROTECTED]> wrote:
> 
> On Jul 19, 2005, at 11:32 AM, Mikaƫl Cluseau wrote:
> 
> > ??? why aren't you adding a css parameter to your Border with a
> > default
> > value?
> 
> How would this achieve what I am looking for?  All this does is shift
> my getStylesheet() from my own base page class to a setStylesheet()
> method in my Border component.  This hardly seems any easier.
> 
> Please feel free to correct.
> 
> --
> Kevin
> 
> 


-- 
The Spindle guy.           http://spindle.sf.net
Get help with Spindle:   
http://lists.sourceforge.net/mailman/listinfo/spindle-user
Announcement Feed:    
http://www.jroller.com/rss/glongman?catname=/Announcements
Feature Updates:            http://spindle.sf.net/updates

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

Reply via email to