我的程序出了什么问题?我认为一切都很好。我的changeKeyValue
方法获取选定的值 'REFERENCE' 并将true
布尔值设置为showReference
. h:panelGroup
但是,如果我使用update="targetPanel"
in ,我的页面将无法呈现p:ajax
。它可以h:panelGroup
在我使用update="entryForm"
.
我错过了什么?
我的页面.xhtml
<h:form id="entryForm">
<p:selectOneMenu value="#{MyBean.keyFactorValue}" required="true" style="width:257px;" id="keyFactorValue">
<f:selectItems value="#{MyBean.selectItemList}" var="type" itemLabel="#{type.label}" itemValue="#{type}"/>
<p:ajax listener="#{MyBean.changeKeyValue}" update="targetPanel" event="change"/>
</p:selectOneMenu>
<h:panelGroup id="targetPanel" rendered="#{MyBean.showReference}">
.......
</h:panelGroup>
</h:form>
KeyFactorValue.java
public enum KeyFactorValue {
REFERENCE("Reference"), FORM_TO("From-To"), FIXED("Fixed");
private String label;
private KeyFactorValue(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
}
MyBean.java
@Scope(ScopeType.CONVERSATION)
@Name("MyBean")
public class MyBean {
private boolean showReference;
public boolean isShowReference() {
return showReference;
}
public KeyFactorValue[] getSelectItemList() {
return KeyFactorValue.values();
}
public void changeKeyValue(AjaxBehaviorEvent e) {
KeyFactorValue type = keyFactor.getKeyFactorValue();
System.out.println("Selected KeyFactorValue : " + type);
switch(type) {
case REFERENCE :{
showReference = true;
break;
}
default :{
showReference = false;
break;
}
}
}
}