On 4/9/09 6:58 AM, Paulo Cesar Reis wrote:
> Hi all,
>
> I'm trying to include the "theme" feature in one of my projects. I was
> wondering which approach is the best.
>
> In JSF2, as we all know, we got the Resource Feature, where you can
> define a resource using library, locale, resourceName and so. Imagine
> that I got the follow resource: cpt-components/tab.css that can be
> retrieved by the page author using the follow:
>
> #{resource['cpt-components:tab.css']}
The EL syntax is not the most flexible for what you're trying to
acomplish. It's convenient, but take note that components such as
graphicImage,
outputStylesheet, etc all accept 'name' and 'library' attributes. These
allow you to specify EL expressions for each part, where as the EL
syntax forces
a literal.
>
> So when this resource is being asked I need to get the current theme
> of my application (database, or whatever, lets says that the current
> theme is 'default'). My resources are organized using the follow pattern:
>
> cpt-resources.jar
>
> - META-INF/resources/cpt-components/default/tab.css
> - META-INF/resources/cpt-components/new_year/tab.css
>
> How to do that?
The easiest would be storing the theme information in the session
(perhaps a HttpSessionBindingListener would be useful to
populate the session when it's created?), then, reference the library
name via expression #{sessionScope.themeName} which would
resolve to default or new_year.
> - I could create a ResourceHandlerImpl (or ResourceManager?), so
> when a resource is being asked, I can add the "/theme_name/" path
> before the resourceName and, I think, everything will work. In this
> approach, how can I override the default Sun ResourceHandler Impl? ( I
> searched for all possibilities on web.xml reading the source of class
> WebConfiguration and my best guess would be
> "facelets.RESOURCE_RESOLVER" but I don't know.)
<faces-config>
<application>
<resource-handler>CustomResourceHandler</resource-handler>
</application>
</faces-config>
CustomResourceHandler would have a public constructor of:
public CustomResourceHandler(ResourceHandler delegate) {
this.delegate = delegate; }
This would allow you to intercept all resource requests, manipulate them
as you see fit and delegate to the
default implementation as necessary.
> - I could design some event-based model to threat the themes
> resources before encoding them, using Application Listeners.
>
> What is the best implementation for theme feature?
Not quite sure what to tell you as far as 'best'. There's probably a
dozen viable ways to 'skin' this cat.
>
> Thanks in advance.