我在实现 MyFaces 2.0 时使用 JSF。在我的网络应用程序中,我希望页面带有“显示更多”按钮。用户获取页面,只有按钮和带有一些信息的隐藏表单(例如带有标签)。当用户单击此按钮时,他会在显示标签的同一页面上看到。当他再次点击标签应该隐藏。
我的页面.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form>
<h:commandButton value="show more" action="#{bean.showOrHide}">
<f:ajax render=":formWithLabel"/>
</h:commandButton>
</h:form>
<hr/>
<h:form id="formWithLabel" rendered="#{bean.show}">
<h:outputLabel value="More information"/>
</h:form>
</h:body>
豆.java:
@ManagedBean
@ViewScoped
public class Bean {
private boolean show;
//getters, setters
public void showOrHide(){
show = !show;
}
}
这段代码似乎不起作用。怎么了?