设置RichFaces的皮肤非常的容易,只需在web.xml中指定一个参数:
<context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>ruby</param-value> </context-param>
有时候想要在运行时动态改变应用的皮肤,这样用户可以选择他们各自喜欢的皮肤并保存起来,下面给出一个方法。
首先用EL表达式来指定皮肤,而不是像上面那样硬编码:
<context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>#{skinBean.skin}</param-value> </context-param>
skinBean是一个类似于下面这样的JSF的Managed Bean:
public class SkinBean {
private String skin;
public String getSkin() {
return skin;
}
public void setSkin(String skin) {
this.skin = skin;
}
}
需要在faces-config.xml中注册它:
<managed-bean> <managed-bean-name>skinBean</managed-bean-name> <managed-bean-class>demo.SkinBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>skin</property-name> <value>ruby</value> </managed-property> </managed-bean>
我们为皮肤设置了默认值并把它保存在session中。
下面可以快速测试一下:
<h:form>
<rich:panel header="I can change skins" style="width: 300px">
<h:panelGrid columns="2">
<h:selectOneListbox id="select" value="#{skinBean.skin}" οnchange="submit()">
<f:selectItem itemLabel="plain" itemValue="plain" />
<f:selectItem itemLabel="emeraldTown" itemValue="emeraldTown" />
<f:selectItem itemLabel="blueSky" itemValue="blueSky" />
<f:selectItem itemLabel="wine" itemValue="wine" />
<f:selectItem itemLabel="japanCherry" itemValue="japanCherry" />
<f:selectItem itemLabel="ruby" itemValue="ruby" />
<f:selectItem itemLabel="classic" itemValue="classic" />
<f:selectItem itemLabel="laguna" itemValue="laguna" />
<f:selectItem itemLabel="deepMarine" itemValue="deepMarine" />
</h:selectOneListbox>
<rich:tabPanel>
<rich:tab label="Tab 1">Tabs also change color</rich:tab>
<rich:tab label="Tab 2">...</rich:tab>
</rich:tabPanel>
</h:panelGrid>
</rich:panel>
</h:form>
好了,看看效果吧:
原文地址:http://mkblog.exadel.com/?p=227,由于比较简单,我这里只是做了意译,你说明白就好了。