1 Reply Latest reply on Mar 10, 2008 9:45 PM by carlpritchett

    Ajax4jsf select update in same page using EntityQuery

    carlpritchett

      Hi,


      I'm trying to ajax enable a seam-gen created application. I have an orderItem where you can select a plant to add to it. I have merged the plant selection page with the orderItem page.


      It almost works - the search for plants updates the results, but when I select a item the original search results (created on page load) are used (not the new ajax rendered search results). I don't know how to update the real model (the page shows the correct results, but it's not what the commandLink picks - like the commandLink is ignoring the ajax update of the search resutls).


      How do I update the search results so the orderItem.instance.plant is set with the correct value?


      Heres my attempt - all objects are seam-generated i.e. EntityHome and EntityQuery:                 


      <ui:define name="body">    
         <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
          <a:outputPanel id="selectedPlantForm">
             <h:form id="orderItem" styleClass="edit">        
                  <rich:panel>
                      <f:facet name="header">#{orderItemHome.managed ? 'Edit' : 'Add'} OrderItem</f:facet>
          
                      <s:decorate id="numberOrderedDecoration" template="layout/edit.xhtml">
                          <ui:define name="label">number Ordered</ui:define>
                          <h:inputText id="numberOrdered"
                                 required="true"
                                    value="#{orderItemHome.instance.numberOrdered}">
                              <a:support event="onblur" reRender="numberOrderedDecoration" bypassUpdates="true"/>
                          </h:inputText>
                      </s:decorate>          
                   
                      <s:decorate id="plantDecoration" template="layout/edit.xhtml">
                          <ui:define name="label">Plant</ui:define>
                          
                          <h:outputText id="plantName" 
                                    value="#{orderItemHome.instance.plant.name}"
                                    rendered="#{orderItemHome.instance.plant != null}">
                          </h:outputText>
                          <h:outputText value="No plant Selected" 
                              rendered="#{orderItemHome.instance.plant == null}"/>
                      </s:decorate>        
                  
                      <div style="clear:both">
                          <span class="required">*</span> 
                          required fields
                      </div>
                  </rich:panel>
                          
                  <div class="actionButtons">
                      <h:commandButton id="save" 
                                    value="Save" 
                                   action="#{orderItemHome.persist}"
                                 disabled="#{!orderItemHome.wired}"
                                 rendered="#{!orderItemHome.managed}"/>  
                                                     
                      <h:commandButton id="update" 
                                    value="Save" 
                                   action="#{orderItemHome.update}"
                                 rendered="#{orderItemHome.managed}"/>
                                                   
                      <h:commandButton id="delete" 
                                    value="Delete" 
                                   action="#{orderItemHome.remove}"
                                 rendered="#{orderItemHome.managed}"/>
                              
                      <s:button id="done" 
                             value="Done"
                       propagation="end"
                              view="/OrderItem.xhtml"
                          rendered="#{orderItemHome.managed}"/>
                          
                      <s:button id="cancel" 
                             value="Cancel"
                       propagation="end"
                              view="/#{empty orderItemFrom ? 'OrderItemList' : orderItemFrom}.xhtml"
                          rendered="#{!orderItemHome.managed}"/>
                  </div>
              </h:form>
          </a:outputPanel>
      
          <h:form id="plantSearch" styleClass="edit">    
              <rich:simpleTogglePanel label="Plant search parameters" switchType="ajax">
              
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">name</ui:define>
                      <h:inputText id="name" value="#{plantList.plant.name}"/>
                  </s:decorate>
      
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">code</ui:define>
                      <h:inputText id="code" value="#{plantList.plant.code}"/>
                  </s:decorate>
              </rich:simpleTogglePanel>
              
              <div class="actionButtons">
                  <a:commandButton id="search" value="Search" action="#{plantList.refresh()}"
                      reRender="searchResults1, selectedPlantForm"/>
              </div>
          </h:form>
          
          <a:outputPanel id="searchResults1">    
              <h:form id="plantSearchResults" styleClass="edit">
              <rich:panel>
                  <f:facet name="header">Plant search results</f:facet>
              <div class="results" id="plantListResults">
              <h:outputText value="No plant exists" 
                         rendered="#{empty plantList.resultList}"/>
                         
              <rich:dataTable id="plantList" 
                          var="plant"
                        value="#{plantList.resultList}" 
                     rendered="#{not empty plantList.resultList}">         
                     
                  <h:column>
                      <f:facet name="header">
                          <s:link styleClass="columnHeader"
                                       value="Plant Id #{plantList.order=='plantId asc' ? messages.down : ( plantList.order=='plantId desc' ? messages.up : '' )}">
                              <f:param name="order" value="#{plantList.order=='plantId asc' ? 'plantId desc' : 'plantId asc'}"/>
                          </s:link>
                      </f:facet>
                      #{plant.plantId}
                  </h:column>
                  <h:column>
                      <f:facet name="header">
                          <s:link styleClass="columnHeader"
                                       value="Name #{plantList.order=='name asc' ? messages.down : ( plantList.order=='name desc' ? messages.up : '' )}">
                              <f:param name="order" value="#{plantList.order=='name asc' ? 'name desc' : 'name asc'}"/>
                          </s:link>
                      </f:facet>
                      #{plant.name}
                  </h:column>
                  <h:column>
                      <f:facet name="header">Action</f:facet>
                          <a:commandLink
                               value="Select #{plant.name} #{plant.plantId}" 
                               action="#{orderItemHome.getInstance().setPlant(plant)}" 
                               reRender="selectedPlantForm, searchResults1" />  
                  </h:column>
              </rich:dataTable>
          
              </div>
              </rich:panel>
             
              </h:form> 
          </a:outputPanel> 
      </ui:define>



      Regards,
      Carl.

        • 1. Re: Ajax4jsf select update in same page using EntityQuery
          carlpritchett

          I discovered the problem - in merging the order item and the plant selection pages I neglected to merge the page.xml files.


          orderItem.page.xml was missing the two params that allow the search criteria to be remembered during the ajax refresh of the search results.


          Adding the following resolves the issue:


             <param name="name" value="#{plantList.plant.name}"/>
             <param name="code" value="#{plantList.plant.code}"/>