user3824693
user3824693

Reputation: 49

How to apply jsf primefaces theme for a single jsf page

I want to apply primefaces Trontastic theme only for one jsf page. I have read answer give on Applying PrimeFaces theme only for one JSF page I have done same changes in my code.

I have downloaded and kept trontastic-1.0.10.jar in WEB-INF\lib folder. Extracted the jar and in the 'resources' folder I created a subfolder called "primefaces-trontastic". In this folder,I have copied the file theme.css from the theme and also the 'images' folder. In my xhtml I have added the below code inside

<h:outputStylesheet library="primefaces-trontastic" name="theme.css" />

But I found no change in my jsf page. Do I need to do anything more?

Upvotes: 0

Views: 1234

Answers (1)

Kukeltje
Kukeltje

Reputation: 12335

I myself did it in a different way (no unzipping, keeping in sync etc... )

PF supports 'dynamic' themes by being able to interpret the theme definition in the web.xml as EL

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>#{myPreferences.theme}</param-value>
</context-param>

By haveing a 'preferences' bean and setting the theme name in there (see the showcase source code, it does exactely this when using the themeswitcher), you can switch. You can e.g. have a

<f:event type="preRenderView" listener="#{myPreferences.chooseTheme"} />

generically in your template an in the chooseTheme method look at the page that is being loaded and set a theme you want. You could (and I did not try this) maybe have a

<f:event type="preRenderView" listener="#{myPreferences.theme('one')"} />

in the generic template, and in a specific view maybe override it with.

<f:event type="preRenderView" listener="#{myPreferences.theme('two')"} />

But I'm not sure if this latter works

Upvotes: 2

Related Questions