Page 1 of 1

chenge theme based on user prifile

Posted: 18 Jul 2014, 13:06
by banto.78
Hi al,

i am following the on-line advices but i am not get along.

I want to change the theme based on the user logged in.

As try i added the theme glass-x.jar and changed the web.xml like this:

Code: Select all

	<context-param>
		<param-name>primefaces.THEME</param-name>
		<param-value>glass-x</param-value>
	</context-param>
and it works.

However i would like to store the theme in the DB. So I have an UserBean (SessionScope) with relative theme attribute and now is:

Code: Select all

	<context-param>
		<param-name>primefaces.THEME</param-name>
		<param-value>#{userBean.theme}</param-value>
	</context-param>
Of course when i load the application no user is logged-in. So i though the theme value default to 'aristo' but i get the following error:

Code: Select all

Caused by: javax.faces.FacesException: Error loading theme, cannot find "theme.css" resource of "primefaces-" library
can you pls tell me where i am worng?

thanks lot!

Re: chenge theme based on user prifile

Posted: 18 Jul 2014, 22:15
by banto.78
i think i found somethign following the code on-line.

However still i am not able to set the theme out of this code:

Code: Select all

<p:themeSwitcher value="#{guestPreferences.theme}" style="width:150px" effect="fade">
						<f:selectItem itemLabel="--Choose Theme--" itemValue=""/>
						<f:selectItems value="#{themeSwitcherBean.themes}"/>
						<p:ajax listener="#{themeSwitcherBean.saveTheme}"/>
				</p:themeSwitcher> 
How can the selectItem in this xhtml can call the set on the ThemeSwtcherBean?

Code: Select all

public void setTheme(String theme) {
        this.theme = theme;
    }
I mean this is not SelectOneMenu component :geek: so the result is that once the listener is called the "theme" on the backing bean is NULL!!

Please help. tks

Re: chenge theme based on user prifile

Posted: 21 Jul 2014, 09:54
by andyba
If you want to ensure that the dynamic theme has a default set the value of the theme property in your bean to "aristo".