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

UI Components for JSF
Post Reply
arnieAustin
Posts: 101
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"
	value="#{themeSwitcher.currentTheme}">
	<p:ajax listener="#{themeSwitcher.saveTheme}" />
	<f:selectItem
		itemLabel="#{messages.getString('application.lbl.theme.select')}"
		itemValue="" />
	<f:selectItems value="#{themeSwitcher.themes}" var="t"
		itemLabel="#{t.displayName}" itemValue="#{t.name}" />
	<p:column><p:graphicImage value="#{theme.image}" /></p:column>
	<p:column>
		<h:outputText styleClass="ui-theme ui-theme-#{theme.name}"
			style="display-block" />
	</p:column>
</p:themeSwitcher>
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

@Named
@SessionScoped
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;
	
	@Inject
	private CurrentUserHolder currentUserHolder;
     
    @Inject
    private ThemeService service;
    
    private String currentTheme;
 
    @PostConstruct
    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.

kwutzke
Posts: 154
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.
PF 8.0, Mojarra 2.3, Wildfly 15

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: nasirpinnacle and 8 guests