themeSwitcher example doesn't work and listener isn't fired

UI Components for JSF
Post Reply
Posts: 103
Joined: 14 Feb 2015, 22:35
Location: Austin, TX

14 Feb 2015, 22:53

I'm using 5.1 and copied the code from the showcase as well as compared the code in the PDF manual.

Though the themeSwitcher list appears and the theme is switching, the graphics aren't appearing as I do not have them. (Where might they be found, btw?)

However, I created a getImage method on the theme object to return the byte stream for a place holder image (in the hopes of figuring out this layout issue):

Code: Select all

    public StreamedContent getImage() {
    	InputStream stream = this.getClass().getResourceAsStream("/resources/images/themes/man-icon.png");
    	return new DefaultStreamedContent(stream, "image/png");
I'm not sure if this is working though, because nothing I do gets the drop down list to allocate a column for the picture. The examples look broken (var names aren't the same and are missing in other places). This is the mark up I have thus far:

Code: Select all

<p:themeSwitcher id="ddlTheme" var="theme" style="width:200px;" effect="fade"
	<p:ajax listener="#{themeSwitcher.saveTheme}" />
		itemValue="" />
	<f:selectItems value="#{themeSwitcher.themes}" var="t"
		itemLabel="#{t.displayName}" itemValue="#{}" />
	<p:column><p:graphicImage value="#{theme.image}" /></p:column>
		<h:outputText styleClass="ui-theme ui-theme-#{}"
			style="display-block" />
The themeSwitcher bean is pretty straight forward and otherwise, seems to be working (though saveTheme is never called).
I'm using CDI with PF.

Code: Select all

public class ThemeSwitcher implements Serializable {
	private static final long serialVersionUID = -2874924104373802376L;
	private static final String UI = "UI";
	private static final String THEME_NAME = "theme-name";
	private static final String DEFAULT_THEME = "bluesky";

	private List<Theme> themes;
	private CurrentUserHolder currentUserHolder;
    private ThemeService service;
    private String currentTheme;
    public void init() {
        themes = service.getThemes();
        currentTheme = DEFAULT_THEME;
    public List<Theme> getThemes() {
        return themes;
    public void setService(ThemeService service) {
        this.service = service;
    public void saveTheme() {
    	if ( currentUserHolder != null && !StringUtils.isEmpty(currentTheme) ) 
    		currentUserHolder.savePreference(UI, THEME_NAME, currentTheme);

	public String getCurrentTheme() {
		return currentTheme;
	public void setCurrentTheme(String currentTheme) {
		this.currentTheme = currentTheme;
If someone could provide some insight on this, it would be much appreciated.

Posts: 178
Joined: 20 Jul 2012, 21:35

10 Nov 2019, 05:50

While this posting is old, the most likely cause is that conversion fails. I have experienced strange things with new-style @FacesConverter not working, but simple @Named + @RequestScoped using implements Converter without generics working.

Put a p:messages or p:growl into the update="" attribute and see what's shown. Other than that, register a phase listener to see when JSF exits its lifecycle.
PrimeFaces 8, Mojarra 2.3, Wildfly 15

Post Reply

Return to “PrimeFaces”

  • Information