Skip to main content

JSF - AJAX does not update JSTL forEach loop (getter before setter)

No replies
lostinspace2011
Offline
Joined: 2007-08-01
Points: 0

I have a tree structure which is navigated via a single selectOneListBox. Each time the user selects and item, its children a displayed in the dropdown field. A breadcrumb trail is also being constructed to allow for navigation back to any of the parent nodes in the tree structure. On each selection I am updating the entire h:panelGroup which seem to work for most of however the bread crumb trail is not updated correctly. I added additional debugging to my treeController and found that the getBreadCrumbs method was consistently called before the setSelectedItemId method. This results in the breadcrumb trail being constructed before the current selected is given the option to update the object model. So the previous selection is always shown in the breadcrumb trail. It seems to be that it is incorrect to call any getter before all setters have completed however this seems to be what is happening. I tried searching online but could not find any solution to this problem.

<ui:define name="content">    
  <f:view>     
    <h:form id="dropdown">
      
    <h:panelGroup id="everything">                   
    <h:commandButton value="Root" styleClass="button" action="#{treeController.displayRootItem}"/>            
    Bread crumbs:         
    <c:forEach var="breadCrumb" items="${treeController.breadCrumbs}">           
       <h:commandButton value="#{breadCrumb.name}" styleClass="button" action="#{treeController.displayBreadCrumb}">             
         <f:setPropertyActionListener value="#{breadCrumb}" target="#{treeController.currentItem}"/>           
       </h:commandButton>         
     </c:forEach>         
     <hr/>         
    
     <h:selectOneListbox id="itemList" value="#{treeController.selectedItemId}" size="10" styleClass="contactList" tabindex="2">           
       <f:selectItems value="#{treeController.items}"/>           
       <f:ajax execute="itemList" render="everything" onevent="eventLog" onerror="errorLog"/>         
     </h:selectOneListbox>                 
     <hr/>
         
     Item : <h:outputLabel value="#{treeController.selectedItemId}" rendered="#{treeController.selectedItemId != 0}"/>         
     Parent : <h:outputLabel value="#{treeController.selectedParentId}" rendered="#{treeController.selectedParentId != 0}"/>         
     <br/>
         
     <h:inputText value="#{treeController.currentItem.name}" rendered="#{treeController.currentItem != null}"/>         
   </h:panelGroup>                
   </h:form>   
  </f:view> 
&lt;/ui:define&gt;<font class="Apple-style-span" face="'Trebuchet MS', Geneva, Verdana, sans-serif"><span class="Apple-style-span" style="line-height: 18px; white-space: normal; "><br type="_moz" /></span></font>