Richface 改皮肤两种方法
2008-12-25 18:01
第一:
<rich:togglePanel id="skin_chooser"
value="#{skinBean.skinChooserState}" switchType="ajax"
stateOrder="s,b">
<f:facet name="s">
<h:panelGroup>
<table cellpadding="0" cellspacing="0"
border="0">
<tbody>
<tr>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
BlueSky
<f:param value="blueSky" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Classic
<f:param value="classic" name="s" />
</h:outputLink>
</td>
<td value="more »" />
</td>
</tr>
</tbody>
</table>
</h:panelGroup>
</f:facet>
<f:facet name="b">
<h:panelGroup>
<table cellpadding="0" cellspacing="0"
border="0">
<tbody>
<tr>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
BlueSky
<f:param value="blueSky" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Classic
<f:param value="classic" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Ruby
<f:param value="ruby" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Wine
<f:param value="wine" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
DeepMarine
<f:param value="deepMarine" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
EmeraldTown
<f:param value="emeraldTown" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Sakura
<f:param value="japanCherry" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Plain
<f:param value="plain" name="s" />
</h:outputLink>
</td>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Default
<f:param value="DEFAULT" name="s" />
</h:outputLink>
</td>
<ui:remove>
<td>
<h:outputLink
value="#{componentNavigator.currentComponent.contextRelativeDemoLocation}">
Null
<f:param value="NULL" name="s" />
</h:outputLink>
</td>
</ui:remove>
<td value="« less" />
</td>
</tr>
</tbody>
</table>
</h:panelGroup>
</f:facet>
</rich:togglePanel>
后台bean:
private String skin;
private Object skinChooserState;
public String getSkin() {
String param = getSkinParam();
if (param!=null) {
setSkin(param);
}
return skin;
}
public void setSkin(String skin) {
this.skin = skin;
}
private String getSkinParam(){
FacesContext fc = FacesContext.getCurrentInstance();
String param = (String) fc.getExternalContext().getRequestParameterMap().get("s");
if (param!=null && param.trim().length()>0) {
return param;
} else {
return null;
}
}
public String changeSkin() {
String param = getSkinParam();
if (param!=null) {
setSkin(param);
}
return null;
}
public Object getSkinChooserState() {
return skinChooserState;
}
public void setSkinChooserState(Object skinChooserState) {
this.skinChooserState = skinChooserState;
}
faces-config:
<managed-bean>
<managed-bean-name>skinBean</managed-bean-name>
<managed-bean-class>org.richfaces.samples.SkinBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>skin</property-name>
<property-class>java.lang.String</property-class>
<value>blueSky</value>
</managed-property>
</managed-bean>
web.xml
<context-param>
<param-name>org.ajax4jsf.SKIN</param-name>
<param-value>#{skinBean.skin}</param-value>
</context-param>
第二种:
不通过url,通过a4j的参数传递
<h:commandLink value="DeepMarine">
<a4j:actionparam name="skin" value="deepMarine"
assignTo="#{skinBean.skin}" />
</h:commandLink>