0

I have a rich tree and it contains few nodes. I have a checkbox beside each node. When I check a checkbox , checkbox pertaining to all the children needs to be checked and when I uncheck all the children have to be unchecked. I have the below code in my xhtml. In the backing bean , I set all the children to checked / unchecked based on the event. The tree is initially in "collapsed" mode. When I click on the checkbox and expand the node , I can see all the children being checked. But when I uncheck / check in expanded mode , the values aren't getting reflected in the child elements. Can you please help in letting me know what I am missing? Thanks.

    <rich:tree id="producttree" switchType="server"
        value="#updateProductBean.deviceServiceTreeRoot}" var="item">
        <rich:treeNode id="productnode">
            <h:selectBooleanCheckbox value="#{item.selected}"
                rendered="#{item.value == null &amp;&amp; item.checkbox == true}"
                valueChangeListener="#{updateProductBean.submitUpdateProduct}">
                <f:attribute name="selectedProductId" id="selectedProductId"
                    value="#{item.paramID}" />
                <f:attribute name="selectedProductName" id="selectedProductName"
                    value="#{item.name}" />
                <a4j:support event="onclick" reRender="producttree,productnode">
                </a4j:support>
            </h:selectBooleanCheckbox>
            <h:outputText value="#{item.name}" rendered="#{item.value == null}" />
        </rich:treeNode>
    </rich:tree>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • i'm guessing its reRendering problem. are you sure the tree is rebuild after the checkbox is checked? – Ellie Fabrero Jul 10 '12 at 09:51
  • Thanks for your response Ellie - I am not sure if the tree is being rebuilt completely. I added the boolean variable pertaining to the checkbox "selected" property as output text. This value is getting changed for the checkbox that I am checking - but not sure if the chold elements are getting re-rendered. – Punter Vicky Jul 10 '12 at 13:13

2 Answers2

3

Try wrapping your h:selectBooleanCheckBox inside a a4j:outputPanel tag then define an id name, then reRender this a4j:outputPanel on your a4j:support tag. If it is still not reRendered try putting ajaxRendered="true" on your a4j:outputPanel this will make it always updated for every ajax request.

Try this.

<rich:tree id="producttree" switchType="server"
                value="#updateProductBean.deviceServiceTreeRoot}" var="item">
                <rich:treeNode id="productnode">
                    <a4j:outputPanel id="panel" ajaxRendered="true">
                        <h:selectBooleanCheckbox value="#{item.selected}"
                            rendered="#{item.value == null &amp;&amp; item.checkbox == true}"
                            valueChangeListener="#{updateProductBean.submitUpdateProduct}">
                            <f:attribute name="selectedProductId" id="selectedProductId"
                                value="#{item.paramID}" />
                            <f:attribute name="selectedProductName" id="selectedProductName"
                                value="#{item.name}" />
                            <a4j:support event="onclick"
                                reRender="producttree,productnode, panel">
                            </a4j:support>
                        </h:selectBooleanCheckbox>
                    </a4j:outputPanel>
                    <h:outputText value="#{item.name}"
                        rendered="#{item.value == null}" />
                </rich:treeNode>
            </rich:tree>
Andy_Lima
  • 129
  • 12
Ellie Fabrero
  • 791
  • 2
  • 16
  • 41
  • Hi Ellie , tried this but this is not updating the checkboxes pertaining to child elements as well :( – Punter Vicky Jul 18 '12 at 16:46
  • try checking if the values of check box inside your nodes are updated, and the tree is rebuild correctly. Since it works on collapse mode. – Ellie Fabrero Jul 19 '12 at 02:00
  • I tried printing the values of the checkboxes inside the backing bean in the method (submitUpdateProduct) that gets invoked on check / uncheck. I am explicitly setting the values of all the child elements to true or false based on whether the parent checkbox is selected or not. The values are set properly. How can I ensure that the tree is rebuilt correctly? Thanks for all your help. – Punter Vicky Jul 19 '12 at 05:56
  • can you use change switchType="ajax"since you are using a4j:support it means that it is fire on ajax request. I'll try to create my own example based on your code and see if it works on mine. – Ellie Fabrero Jul 20 '12 at 01:17
  • Hi Ellie, the issue got fixed when I set the tree to null in the backing bean. The tree got rendered properly after that. Thanks a lot for your assistance!! BTW - gave you the bounty :) – Punter Vicky Jul 24 '12 at 19:13
-1

It Render the whole one level to which you click on tree so for that if you are having any ajax call then it will call the very first node and will skip for rest. The whole story is mapping the whole level.

Bhup
  • 1