2 Replies Latest reply on Jul 2, 2008 10:16 AM by Yurii Kartsev

    tree reRenders a4j:outputPanel TWICE!

    Yurii Kartsev Apprentice

      Good afternoon, dear RichFaces developers!

      I have noticed that my rich:tree comonent reRenders a4j:outputPanel twice when I click on a node. I can't understand why does it happens. Help me please.

      Here is my tree code:

      <h:form id="structureTree_form">
      
       <rich:tree style="width:250px" id="structureTree" styleClass="tree" switchType="ajax" ajaxSubmitSelection="true"
       showConnectingLines="true" changeExpandListener="#{treeMan.onDepartmentTreeExpandStaff}"
       nodeSelectListener="#{treeMan.onDepartmentTreeSelectStaff}" stateAdvisor="#{departmentTreeStateAdvisor}"
       reRender="staffDataTable_FormPanel">
       <rich:recursiveTreeNodesAdaptor roots="#{treeMan.departmentsTreeRoots}" var="item" nodes="#{item.nodes}" />
       </rich:tree>
      
      </h:form>


      Here is my staffDataTable_FormPanel which is reRendered from the tree:
      <a4j:outputPanel id="staffDataTable_FormPanel">
       <h:form id="staffDataTable_Form">
       <rich:scrollableDataTable id="staffDataTable" height="400px" rowKeyVar="rkv" binding="#{staffSDTableMan.sdTable}"
       selection="#{staffSDTableMan.scrollableDataTableSelection}" onRowMouseOver="this.style.backgroundColor='#B5CEFD'"
       onRowMouseOut="this.style.backgroundColor='#{org.richfaces.SKIN.tableBackgroundColor}'" rowClasses="sdt_row1,sdt_row2"
       selectedClass="sdt_row_selected" activeClass="sdt_row_active" width="500px" rows="0" columnClasses="sdt_col" frozenColCount="1"
       value="#{amBean.employeeListMan.staffEmployees}" var="employee" sortMode="single">
      
       <a4j:support event="onRowClick" onSubmit="this.style.backgroundColor='#000000" actionListener="#{staffSDTableMan.sdtRowSelected}"
       reRender="editWorker_panel_output" />
      
       <rich:column id="firstName">
       <f:facet name="header">
       <h:outputText styleClass="sdt_head" value="#{muiBundle.sdTableFirstName}" />
       </f:facet>
       <h:outputText value="#{employee.firstName}" />
       </rich:column>
      
       <rich:column id="lastName">
       <f:facet name="header">
       <h:outputText styleClass="sdt_head" value="#{muiBundle.sdTableLastName}" />
       </f:facet>
       <h:outputText value="#{employee.lastName}" />
       </rich:column>
      
       <rich:column id="sex">
       <f:facet name="header">
       <h:outputText styleClass="sdt_head" value="#{muiBundle.sdTableSex}" />
       </f:facet>
       <h:outputText value="#{employee.sex}" />
       </rich:column>
      
       <rich:column id="birthDate">
       <f:facet name="header">
       <h:outputText styleClass="sdt_head" value="#{muiBundle.sdTableBDate}" />
       </f:facet>
       <h:outputText value="#{employee.birthDate}" />
       </rich:column>
      
       <rich:column id="birthPlace">
       <f:facet name="header">
       <h:outputText styleClass="sdt_head" value="#{muiBundle.sdTableBPlace}" />
       </f:facet>
       <h:outputText value="#{employee.birthPlace}" />
       </rich:column>
       </rich:scrollableDataTable>
      
       <BR style="text-size: 3px;" />
      
       <a4j:commandButton disabled="true" action="#{staffSDTableMan.makeSomethingWithSelection}" value="#{muiBundle.buttonOrder}"></a4j:commandButton>
       <h:outputLink id="editStaffLink" value="/AHRS/editpersdata.jsf" styleClass="txtlink" target="_blank">
       <h:outputText value="#{muiBundle.commonEdit}" />
       </h:outputLink>
      
       </h:form>
      </a4j:outputPanel>


      Here is my onDepartmentTreeSelectStaff method(as you see, it just sets one variable of another managed bean to selected node):
      public void onDepartmentTreeSelectStaff(NodeSelectedEvent event)
      {
       UITree tree = (UITree)event.getComponent();
      
       if(tree == null) return;
      
       DepartmentTreeNode selectedNode = (DepartmentTreeNode)tree.getRowData();
      
       ActionsManager am = (ActionsManager)TreeManager.getBean(WebConst.MAIN_MBEAN_NAME);
       am.getEmployeeListMan().setParameter4Staff(selectedNode.getDepartmentAllTree());
       System.out.println("parameter setParameter4Staff SET to " + selectedNode.getDepartmentAllTree().getName());
      }


      And here is my staffEmployees getter:
      public List<Employee> getStaffEmployees()
      {
       refresh4Staff();
       return this.employees;
      }


      refresh4Staff method gets employees list from the DB using variable parameter4Staff which was set earlier and then NULLS it(makes equal null). Thus, when it's called for the first time - everything goes fine, but when the table is reRendered for the second time, parameter4Staff is null already and the data retrieved from the DB is wrong.

      Why does it refresh twice?

      Thanks in advance!