My class is as follows:
public class TestBean implements Serializable{
private int id;
private String name;
private boolean showOut;
public TestBean(){
showOut=false;
}
public void submit(){
System.out.println("id-----"+id);
}
public void whatsTheName(AjaxBehaviorEvent e){
System.out.println("listener called");
if(id==0){
name="Dog";
showOut=true;
}
else if(id==1)
name="Cat";
else
name="Bird";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
System.out.println("name called-----"+name);
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isShowOut() {
System.out.println("showOut called----"+showOut);
return showOut;
}
public void setShowOut(boolean showOut) {
this.showOut = showOut;
}
}
和XHTML正常工作是:呈現未在JSF
<!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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form id="frm1">
<h:selectOneMenu value="#{testBean.id}">
<f:selectItem itemLabel="Dog" itemValue="0"></f:selectItem>
<f:selectItem itemLabel="Cat" itemValue="1"></f:selectItem>
<f:selectItem itemLabel="Bird" itemValue="2"></f:selectItem>
<f:ajax execute="@form" event="change"
listener="#{testBean.whatsTheName}" render=":frm2:out"></f:ajax>
</h:selectOneMenu>
</h:form>
<br></br>
<br></br>
<h:form id="frm2">
<h:outputText id="out" value="#{testBean.name}" rendered="#{testBean.showOut}"/>
</h:form>
我想,當選擇了 '狗',只顯示輸出框。但是,即使特定變量的值在輔助bean上正確設置,outputText上的渲染也不起作用。