We use 2 mechanisms. The first is the aforementioned Sell component to do the main CSS for the look and feel to the site.
Then each page has a Block component that contains the page specific CSS. This
is then rendered once in the page. That way we can override the default CSS or
make specific reference to assets or components on that page.
Rob Cole
Ted Steen <[EMAIL PROTECTED]>
25/08/2005 09:07
To
Tapestry users <[email protected]>
cc
Please respond to
"Tapestry users" <[email protected]>
Subject
Re: CSS in page or component
What if one have Assets that need to be referenced in the css?
How is that solved?
On 8/25/05, Ron Piterman <[EMAIL PROTECTED]> wrote:
> What I do to resolve this is the following:
>
> Each component which wants to "contribute" a css, implements an
> Interface named IStyleable.
>
> The border goes through all components of the page and checks them.
> For each one which implements the IStyleable interface (which is only a
> marker, and has no methods to implement) it reaches for the "css" asset,
> and adds it to a set of assets. (see code at the end)
>
> This whole thing happens only once per page instance, so performance is
> not an issue.
>
> in the border I define
> <html jwcid="@Shell" stylesheets="ognl:stylesheets" ...>
>
> Thats it. Works very nice for me.
>
> Cheers,
> Ron
>
> ===================================
>
> public class Border extends BaseComponent implements IStyleable {
>
> private IAsset[] _stylesheets;
>
> public IAsset[] getStylesheets() {
> if (_stylesheets == null) {
> Set s = new HashSet();
> getStylesheets(getPage(),s);
> _stylesheets = new IAsset[s.size()];
> System.arraycopy(s.toArray(),0,_stylesheets,0,s.size());
> }
> return _stylesheets;
> }
>
> private void getStylesheets(IComponent c, Set s) {
> if (c instanceof IStyleable)
> addStylesheet(c,s);
> for (Object cc : c.getComponents().values())
> getStylesheets((IComponent)cc, s);
> }
>
> private void addStylesheet(IComponent s, Set set) {
> IAsset asset = s.getAsset("css");
> if (!set.contains(asset))
> set.add(asset);
> }
> }
>
>
> ציטוט Tomáš Drenčák:
> > Hi,
> > I'd like to ask how can I include a css file into a component or even
> > a page. I use own Border component with Shell. Stylesheets could be
> > imported there, but what if I want to include css specific to page or
> > component?
> >
> > thanks
> > tomas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
/ted
--
This e-mail may contain confidential and/or privileged information. If you are
not the intended recipient (or have received this e-mail in error) please
notify the sender immediately and destroy this e-mail. Any unauthorized
copying, disclosure or distribution of the material in this e-mail is strictly
forbidden.
