<h:panelGroup rendered="#{userBean.loggedIn}"> ... </h:panelGroup> <h:panelGroup rendered="#{!userBean.loggedIn}"> ... </h:panelGroup> 超过两个选项的情况,最好使用组件(myfaces) <t:panelStack selectedPanel="#{userBean.status}"> <h:panelGroup id="new">...</h:panelGroup> <h:panelGroup id="loggedIn">...</h:panelGroup> <h:panelGroup id="loggedOut">...</h:panelGroup> </t:panelStack>方法的返回字符串的值 *这里id对应的值应该为userbean.getStatus private String status; public String getStatus() { if(status==null||("").equals(status)) { return "new"; } if(user.loggedIn) { return "LoggedIn"; } if(!user.loggedIn) { return "LoggedOut"; } } 补: myfaces的jar lib/tomahawk-1.1.8.jar <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>