reRender checkboxes problem

I have a menu (screen below) where the two section are refreshed using rerender.
Depending to main object the sections are refreshed. The input checkboxes checked for the 1st main object are deleted when I change the main object.
Is there a way to keep the boxes checked after rerendring ?

enter image description here

EDIT

Here is the sections that I reRender and to get the boxes checked I use JS and onclick event.

    <!---------------------------------------------------------->

    <apex:pageBlock >
        <apex:pageBlockSection id="sec2Title" title="Select Child Object" />
        <ul class="filetree treeview" id="browser">
            <apex:form >
                <apex:outputPanel id="objChildren">
                    <ul id="boxesChildObj">
                        <apex:repeat value="{!children}" var="s">
                            <input type="checkbox" class="{!s}" /> <label id ="{!s}"  onclick="childToFields(this.id);" style="cursor:pointer;"> {!s} </label> <br/>
                        </apex:repeat>
                    </ul>    
                </apex:outputPanel>

            </apex:form>
        </ul>
    </apex:pageBlock>

The result for 3 fields for example is :

enter image description here

Answer

To keep checkboxes checked/unchecked after rerender you will have to store their checked value somewhere in the code of your controller.

And every time you check/uncheck a checkbox you will have to update those values in your code as well. For checkbox you can then use:

<apex:inputCheckbox selected="{!yourMethodThatReturnsIfCheckboxShouldBeSelected}"/>

Attribution
Source : Link , Question Author : Amine Darkaoui , Answer Author : Novarg

Leave a Comment