0 Replies Latest reply on Dec 13, 2007 5:58 PM by suprernie

    richfaces tree problem with selectBooleanCheckbox

    suprernie

      I have a problem when using the <rich:tree> component plus the <rich:treeNodesAdaptor> with switchType="ajax" on the tree tag.

      For some reason in certain scenarios the model object bound to a child component in the tree will not update correctly.

      In my scenario I have a <h:selectBooleanCheckbox> component as a child of one of the <rich:treeNode>. The <h:selectBooleanCheckbox> has an <a4j:support> tag to rerender another ajax region on a "onclick" event.

      The problem occurs whenever a branch has a single leaf and there are more branches below it. Opening the branch and clicking the single box should update the value of my model object since the model object is value binded via the <h:selectBooleanCheckbox>, but it doesn't.

      In other branches where there is more than one leaf; no problems. The model object is updated correctly. The screwy workaround is that if you expand one of the lower branches then click on the single leaf branch checkbox it works. Weird and very lengthy to explain.

      Here's a code sample of my facelets page.

       <a4j:outputPanel id="a4jTreeRegion" ajaxRendered="false">
       <h:form id="msTreeForm">
       <rich:tree id="marketSegmentTree"
       switchType="ajax"
       showConnectingLines="false"
       immediate="false"
       componentState="#{treeTest.msTreeState}"
       stateVar="treeState">
       <rich:treeNodesAdaptor id="ms" nodes="#{treeTest.msegs}" var="ms">
       <rich:treeNode ignoreDupResponses="true"
       id="marketSegmentTreeNode">
       <h:outputText value="#{ms.name}" />
       </rich:treeNode>
      
       <rich:treeNodesAdaptor id="values" var="value" nodes="#{ms.values}">
       <rich:treeNode id="marketSegmentTreeNodeOne" ignoreDupResponses="true">
      
       <h:selectBooleanCheckbox id="msCheckBox1" value="#{value.checkBoxClicked}">
       <a4j:support
       event="onclick"
       ajaxSingle="true"
       reRender="widgetPanel"
       immediate="false"
       action="#{treeTest.viewWidget(value)}"/>
       </h:selectBooleanCheckbox>
      
       <h:outputText value="#{value.name}" />
      
       </rich:treeNode>
       </rich:treeNodesAdaptor>
       </rich:treeNodesAdaptor>
       </rich:tree>
       </h:form>
      
       </a4j:outputPanel>
      
      


      Notice the <h:selectBooleanCheckBox>. Here's the code to the backing bean. In the findWidgets() method I create the ArrayList that populates the tree. Node 2 is where the tree will have only one leaf and where I have issues.

      @Name("treeTest")
      @Scope(ScopeType.PAGE)
      @Synchronized
      public class TreeTest {
      
       @In (required=false, scope=ScopeType.PAGE)
       @Out (required=false, scope=ScopeType.PAGE)
       private List<Widget> msegs;
      
       @Out (required=false, scope=ScopeType.PAGE)
       private Widget widget;
      
       // Component Binding to save widget tree state
       private TreeState msTreeState;
      
       private void findWidgets(){
       msegs = new ArrayList<Widget>();
      
       //Add Node 1
       List<Widget> msSubs = new ArrayList<Widget>();
       Widget msSub = new Widget("Leaf 1.1",null);
       msSubs.add(msSub);
       msSub = new Widget("Leaf 1.2",null);
       msSubs.add(msSub);
      
       Widget ms = new Widget("Branch 1", msSubs);
       msegs.add(ms);
      
       //Add Node 2
       msSubs = new ArrayList<Widget>();
       msSub = new Widget("Leaf 2.1",null);
       msSubs.add(msSub);
      
       ms = new Widget("Branch 2", msSubs);
       msegs.add(ms);
      
       //Add Node 3
       msSubs = new ArrayList<Widget>();
       msSub = new Widget("Leaf 3.1",null);
       msSubs.add(msSub);
       msSub = new Widget("Leaf 3.2",null);
       msSubs.add(msSub);
      
       ms = new Widget("Branch 3", msSubs);
       msegs.add(ms);
      
       }
      
       public List<Widget> getMsegs() {
       if(msegs == null){
       findWidgets();
       }
       return msegs;
       }
      
       public void setMsegs(List<Widget> msegs) {
       this.msegs = msegs;
       }
      
       public TreeState getMsTreeState() {
       return msTreeState;
       }
      
       public void setMsTreeState(TreeState msTreeState) {
       this.msTreeState = msTreeState;
       }
      
      
       public String viewWidget(Widget w){
       widget = w;
       return "";
       }
      
       public Widget getWidget() {
       return widget;
       }
      
       public void setWidget(Widget widget) {
       this.widget = widget;
       }
      
      }
      


      Here's the code to the Widget model:
       public class Widget {
       private String name;
       private List<Widget> values;
       private boolean checkBoxClicked;
      
       public Widget(String name, List<Widget> values) {
       super();
       this.name = name;
       this.values = values;
       this.checkBoxClicked = false;
       }
      
       public String getName() {
       return name;
       }
       public void setName(String name) {
       this.name = name;
       }
       public List<Widget> getValues() {
       return values;
       }
       public void setValues(List<Widget> values) {
       this.values = values;
       }
       public boolean isCheckBoxClicked() {
       return checkBoxClicked;
       }
       public void setCheckBoxClicked(boolean checkBoxClicked) {
       this.checkBoxClicked = checkBoxClicked;
       }
      
       }
      



      Here are details about libraries.

      Richfaces 3.1.2.GA
      Seam 2.0
      JBoss 4.2.1 [using JSF Sun RI]

      In addition this does not occur for me when using switchType="client". Haven't tried server yet.

      I've seen the following error in the log when clicking the tree,

      17:28:32,967 ERROR [STDERR] TreeRendererBase.encodeAjaxChildren()[ms_:2]

      but I'm not sure if related. I've seen in JIRA that this error was resolved for richfaces 3.1.3, but not sure if related to my issue.

      Any help would be much appreciated.