简体   繁体   中英

ValueChangeListener of h:selectBooleanCheckbox never invoked

Can someone tell me why the valueChangeListener method is never fired?

  <h:form>
   <h:selectBooleanCheckbox
    value="#{reaCtrl.update}"
    valueChangeListener="#{reaCtrl.updateC}" onclick="submit()"> 
    </h:selectBooleanCheckbox>
  </h:form>

The method updateC looks like that:

public void updateC(ValueChangeEvent event) {
         System.out.println("testC");
}

Thx

Your updateC method will be invoked by the JSF implementation after the Process Validation Phase, so my guess is that you have some other validation errors which causes that your method is never invoked.

You can place <h:messages/> tag in start of your form to display all conversion / validation errors.

However, in case you want to bypass that validation, you can use the immediate attribute like this:

<h:selectBooleanCheckbox
value="#{reaCtrl.update}" immediate="true"
valueChangeListener="#{reaCtrl.updateC}" onclick="submit()"> 
</h:selectBooleanCheckbox>

Adding that attribute will fire a Value Change events after Apply Request Values Phase, which means that your method updateC will be invoked in that phase, after the method xecutes you should skip to the Render Response Phase, so you need to modify your method like this:

public void updateC(ValueChangeEvent event) {
         System.out.println("testC");
         FacesContext context = FacesContext.getCurrentInstance();
         context.renderResponse();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM