我想根据复选框的值制作一个输出文本;这是我的代码:
<?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:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="../WEB-INF/templates/template.xhtml">
<ui:define name="content">
<h:form id="formModifClt">
<h:outputText value="voulez-vous modifier cette image ?"/>
<h:selectBooleanCheckbox value="#{clientController.modifierImage}" >
<f:ajax event="click" listener="#{clientController.onChangeCheckBox()}" render="textPanel" />
</h:selectBooleanCheckbox>
<p:outputPanel id="textPanel" autoUpdate="true" >
<h:outputText value="Oui" rendered="#{clientController.modifierImage}" />
<h:outputText value="Non" rendered="#{!clientController.modifierImage}" />
</p:outputPanel>
<p:outputPanel autoUpdate="true" >
<h:outputText value="Logo" rendered="#{clientController.modifierImage}" id="logo" />
<p:fileUpload id="up" fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
sizeLimit="100000"
required="true"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" rendered="#{clientController.modifierImage}"/>
</p:outputPanel>
<p:commandButton action="#{clientController.modifClient()}" value="Modifier" ajax="false"/>
</h:form>
</ui:define>
</ui:composition>
</body>
我的问题是用户第一次单击复选框时,值没有改变,并且 onChangeCheckBox() 没有工作。从第二次开始,它工作正常。注意:我不想在 javascript 中执行此操作,因为我根据布尔复选框完成了其他处理。
这是我的控制器:
public void onChangeCheckBox () {
System.out.println("modifierImage="+modifierImage);
}
/**
* @return the modifierImage
*/
public boolean isModifierImage() {
return modifierImage;
}
/**
* @param modifierImage the modifierImage to set
*/
public void setModifierImage(boolean modifierImage) {
this.modifierImage = modifierImage;
}
使用balusC的解决方案更好(第一次点击时它不会给出一个检查过的checkButton)但问题仍然存在!