2 Replies Latest reply on Sep 18, 2008 12:33 PM by hansfl

    Custom control in TreeNode

    hansfl

      Hi,

      I am using a custom control as a child in a TreeNode.

      The problem I get is that it looks to be using the same object instance of my custom control when it is present several times in the tree. So changing value in one control also changes the value in the others.

      I have confirmed this by debugging and seing how many instances of my custom control are created.

      Are there any specific things I need to do when creating a custom control that is being used in a treenode?

      Here is the jsf markup for parts of the tree:

      <rich:tree id="uitree" binding="#{todoPageBean.toDoTree}"
       style="width:100%"
       switchType="ajax" rowKeyVar="rowKey"
       nodeSelectListener="#{todoPageBean.nodeSelected}"
       onselected="rtnOnNodeSelection(event)"
       adviseNodeSelected="#{todoPageBean.adviseNodeSelected}"
       adviseNodeOpened="#{todoPageBean.adviseNodeOpened}"
       dropListener="#{todoPageBean.nodeDropped}"
       changeExpandListener="#{todoPageBean.nodeExpandCollapse}"
       >
       <rich:recursiveTreeNodesAdaptor id="itemNode"
       var="itemNode"
       nodes="#{itemNode.children}"
       roots="#{todoPageBean.treeModel.root.children}"
       >
       <rich:treeNode rendered="#{itemNode.nodeType.class.name == 'com.mycompany.model.tree.RtnDefaultNodeType'}"
       onkeyup="rtnDoTreeNodeAction(event, this)"
       id="deftreenode"
       dragType="default"
       acceptedTypes="default, resource"
       >
       <rich:inplaceInput value="#{itemNode.name}"
       id="deftreenodeinput"
       onviewactivated="rtnDefToDoEditComplete(event)"
       inputWidth="300px"
       selectOnEdit="true"
       styleClass="content"
       viewClass="content"
       viewHoverClass="content"
       changedClass="content"
       changedHoverClass="content"
       controlClass="content"
       controlHoverClass="content"
       controlPressedClass="content"
       editClass="content"
       editEvent="ondblclick"
       style="background-color: #{itemNode.nodeType.colour}"/>
       <rich:dndParam name="defdraglabel" type="drag" value="#{itemNode.name}" />
       </rich:treeNode>
       <rich:treeNode id="listlookuptreenode"
       rendered ="#{itemNode.nodeType.class.name == 'com.mycompany.model.tree.RtnListLookupNodeType'}">
       <h:outputLabel styleClass="content"
       value="#{itemNode.tableName}: " />
       <rtn:inccombobox id="lookuptreecontrol" width="320" height="20"
       tableName="#{itemNode.tableName}" fieldName="name"
       dropDownParentName="getDocBody()"
       valueChangeListener="#{todoPageBean.subNodeNamesChanged}"
       query="#{itemNode.tableQuery}"
       >
       <a4j:support event="onchange" reRender="#{todoPageBean.defaultReRender}" />
       </rtn:inccombobox>
       </rich:treeNode>
      </rich:recursiveTreeNodesAdaptor>
      
       </rich:tree>

      all controls are working fine except for the rtn:inccombobox one which is my custom control

      Thanks in advance for your help

      Hans Fladsrud


        • 1. Re: Custom control in TreeNode
          nbelaevski

          Hello,

          Your component should implement EditableValueHolder or IterationStateHolder so that it can store state between different nodes in tree. See: org.ajax4jsf.component.UIDataAdaptor.saveChildState(FacesContext, UIComponent, Map<String, SavedState>) for more information.

          • 2. Re: Custom control in TreeNode
            hansfl

            Thanks for your reply,

            I initially thought each component in each displayed node would be represented by different instances and not 1 that was shared.

            Got the component working properly now.

            One of the problems was that the value of the control was not set properly on each request as the html field containing the value was not the same name as the client id of the control.

            Also had to change the ValueExpressions in some properties to be calculated each time they are being called, and not use instance variables when to keep the values from the ValueExpressions.

            Thanks alot for your help

            Hans