checkboxserver-sideicefaces-1.8

icefaces htmlselectbooleancheckbox uncheck not working


I am using icefaces 1.8.2 and i have a HtmlBooleanCheckbox on my page that I need to uncheck when certain circumstances are met.

the checkbox on the page is like this

<ice:selectBooleanCheckbox id="accepttermscheckbox"
    binding="#{managedBean.termsAgreement}"
    validator="#{managedBean.validateAgreement}">
</ice:selectBooleanCheckbox>

and the binded object is a property of the managed bean with proper getter and setter

private HtmlSelectBooleanCheckbox termsAgreement;

i can check the checkbox in code, validator works fine and all the stuff i do with it are ok too but I just cant find a way to uncheck it on the server side.

I tried:

termsAgreement.setValue(Boolean.FALSE)
termsAgreement.setValue(null)
termsAgreement.setSelected(false)

but nothing works. Even if I debug it it shows value = null but when the page renders it still appears checked. Once I check it I just cant get it unchecked unless I click it manually on the page.

funny thing is that

termsAgreement.setValue(Boolean.TRUE)

works fine.

Anyone any tips how I can uncheck it server side on the binded object? Thank you in advance for help.


Solution

  • You are facing a common issue faced by ICEfaces/JSF developers.

    First of all, you need to understand how JSF lifecycle works.

    Following is a good article to read.

    http://www.ibm.com/developerworks/library/j-jsf2/

    For your case, bind a value to <ice:selectBooleanCheckbox>.

    For example value="#{managedBean.termsAgreed}".

    <ice:selectBooleanCheckbox id="accepttermscheckbox"
        binding="#{managedBean.termsAgreement}"
        validator="#{managedBean.validateAgreement}"
        value="#{managedBean.termsAgreed}">
    </ice:selectBooleanCheckbox>
    

    Do not try to change the value from the component. Always change value from the value binding. In this example, you must change the value termsAgreed.

    If your action/actionListener is not immediate, i.e `immediate="false", which is the default value, then changing the value in server-side will check/uncheck checkbox component.

    If you are using immediate="true", then you must call resetValue() method in your component, HtmlSelectBooleanCheckbox:

    termsAgreement.resetValue();
    

    Ideally, you shouldn't call setValue() methods in components. You will understand it when you understand the JSF lifecycle.

    Hope this will help!