prime faces主题切换器:如何向我的项目添加主题

时间:2013-02-22 10:09:05

标签: primefaces

查看我的代码

theme.xhtml

<h:form>
<h:panelGrid>
    <p:themeSwitcher style="width:165px" effect="fade" var="th" id="themePreview" >  
        <f:selectItem itemLabel="Choose Theme" itemValue="" />  
        <f:selectItems value="#{themeBean.themesList}" var="theme" itemLabel="#{theme.name}" itemValue="#{theme}"/>  

        <p:column>  
            <p:graphicImage value="images/#{th.image}"/>  
        </p:column>    
        <p:column>  
            #{th.name}  
        </p:column>  
    </p:themeSwitcher>  
    </h:panelGrid>
    </h:form>

ThemeBean

themesList= new ArrayList<Theme>();     
    themesList.add(new Theme("afterdark","afterdark.png"));
    themesList.add(new Theme("aristo","aristo.png"));
    themesList.add(new Theme("eggplant","eggplant.png"));
    themesList.add(new Theme("humanity","humanity.png"));
    themesList.add(new Theme("sunny","sunny.png"));

}

public List<Theme> getThemesList() {
    return themesList;
}

public void setThemesList(List<Theme> themesList) {
    this.themesList = themesList;
}

Theme.java

private String name;
private String image;

public Theme(String name, String image)
{
    this.setImage(image);
    this.setName(name);
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}   

我遵循了主要面孔的例子。

我在构建路径xml中也配置了主题jar

但我在主题切换器(列表框)中没有得到选择

任何人都可以建议我做什么

1 个答案:

答案 0 :(得分:1)

请参阅Primefaces Theme Switcher Example

他们展示了如何编写这个非常简单的例子。

这里有一个更好的教程Theme tutorial