Hi,
I really like the new theme stuff but I'm having some trouble getting it to work as I want / expect. My site starts with a simple a log-in page which is rendered with the default skin. I then progress to one section of the site for, example /mysite/a/index.xhtml, and select a new theme with a p:themeSwitcher. The skin is correctly applied and looks great, everything under /a gets styled with the selected theme. I then switch to a different part of the site, for example /mysite/b/index.xhtml, and the default theme is used again.
I noticed that there was a cookie called jquery-ui-theme which had the path of /mysite/a/ so I quickly wrote a filter to set a cookie with the path /mysite/ which lets me programatically set the theme but only if there is a p:themeSwitcher on every page.
I would like to be able to allow an administrator to set the theme site wide, for every user, without having a theme swither on every page. I think I could probably achieve something like this by downloading all the theme packages but that seems long winded as PF comes bundled with all the themes (although I can't see where).
Programatic theme selection
-
- Posts: 47
- Joined: 19 Apr 2010, 19:09
- Location: Gloucester, UK
PrimeFaces 3.0.1, Mojarra 2.1.3, GlassFish 3.1.1, Netbeans 7.0, Firefox 7
Hi,
The best way is to store selected theme name or path in a session scoped bean (user settings) and read themes from this bean only.
The best way is to store selected theme name or path in a session scoped bean (user settings) and read themes from this bean only.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
-
- Posts: 47
- Joined: 19 Apr 2010, 19:09
- Location: Gloucester, UK
Thanks, I don't think I phrased my initial question very well.
If I download the themes and bundle them with my application I can completely skin it simply by setting the path to the approprate CSS (as shown here http://www.primefaces.org/themes.html). The path to the skin is trivial to set programatically; the problem is that if I wanted to offer all 26 skins I'd have to download all the skin bundles and include them with my application. Using p:themeSwitcher I don't have to download or bundle anything with my application but I do have to have a p:themeSwitcher on every page in order to apply the skin. The situation I'm trying to avoid is being lumbered with having to keep a dozen skins that I've bundled with my application up to date with each new release of PF.
If I download the themes and bundle them with my application I can completely skin it simply by setting the path to the approprate CSS (as shown here http://www.primefaces.org/themes.html). The path to the skin is trivial to set programatically; the problem is that if I wanted to offer all 26 skins I'd have to download all the skin bundles and include them with my application. Using p:themeSwitcher I don't have to download or bundle anything with my application but I do have to have a p:themeSwitcher on every page in order to apply the skin. The situation I'm trying to avoid is being lumbered with having to keep a dozen skins that I've bundled with my application up to date with each new release of PF.
PrimeFaces 3.0.1, Mojarra 2.1.3, GlassFish 3.1.1, Netbeans 7.0, Firefox 7
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
PrimeFaces showcae also keeps the theme preference of user in a session scope bean and then include the skin css as;
ThemeSwitcher is mostly for development purposes and it supports jquery ui themes only not the new themes of PrimeFaces like casablanca or bluesky.
Also themes do not depend on PrimeFaces releases, they won't be updated with each PrimeFaces release. So you don't need to change themes when you update to a new PrimeFaces version.
Code: Select all
<link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/#{guestPreferences.theme}/skin.css" />
Also themes do not depend on PrimeFaces releases, they won't be updated with each PrimeFaces release. So you don't need to change themes when you update to a new PrimeFaces version.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 48 guests