I have defined three themes in an xpage application, a blue theme, a red theme, and a green theme respectively. I can obviously apply any of these to the entire application via the default theme setting in the application properties. However, if I want to give an end user the ability to select which color theme to use during their session is there some way to programmatically do that (is there some global property that can be set)?
Along those same lines, if I want just one particular xpage to use a different theme than the rest of the application how is that accomplished? I have tried setting the “Theme” property under the Style options for an xpage but that has had no effect.
Subject: Re: Dynamically change theme
I haven’t tried it, but according to the Domino Designer wiki (the same module as on an XPages course I went on), you should be able to use context.setSessionProperty(“xsp.theme”, themeName)
Have you tried that? I’d be interested to know if it works, because I’m planning to do a similar thing.
Here’s the page:
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-18
Regards
Paul
Subject: context.setSessionProperty(“xsp.theme”, themeName)
Thanks for suggesting the use of context.setSessionProperty(“xsp.theme”, themeName). It does indeed work to change the theme, but I am having a problem getting the web page to redisplay with the specified theme in a timely fashion.
For example, I have added a combo box to my xpage and assigned three values to it that represent the available themes. For the data binding of the field I assigned it to a session scope called “selectedTheme”. Then in the onchange event I have it execute a script: context.setSessionProperty(“xsp.theme”, sessionScope.get(“selectedTheme”)). However, despite the fact that I set the server option to do a full update the page does not re-display with the selected theme until I manually refresh the page or click on a link to another xpage in the application. I’ve tried adding context.reloadPage() or Print(“”) statements to the onchange event but those provided no help either.
I’m so very close but yet so far away. Any suggestions?
Subject: Reloading Page
I’m not sure if this will work, but it sounds like context.reloadPage is not doing a fll refresh of the page or something is getting cached.
Perhaps forcing it to a specific page will resolve it. You could do:
var url=@LeftBack(database.getHttpURL(),“/”)+facesContext.getExternalContext().getRequestContextPath();
facesContext.getExternalContext().redirect(url+context.getUrl())
This basically rebuilds the whole URL and uses the facesContext object to redirect. Alternatively, pushing the user to a specific page using context.redirectToPage() may get over the cache problem.
Subject: Got it working
Yup, redirecting back to the same page is ultimately what I had to do to have it immediately redisplay with the selected theme. So the code for the onchange even of the combo box ended up being the following:
context.setSessionProperty(“xsp.theme”, sessionScope.get(“selectedTheme”));
context.redirectToPage(context.getUrl().toString());
Thanks for your help!