4 Replies Latest reply on Feb 2, 2011 3:04 PM by sudda_1

    Issue when submitting after AJAX call

    sudda_1 Newbie

      Are the updates done on page after AJAX call available on a post (i.e JSF submit) ?




      • <a4j:commandLink value="Populate People Table" actionListener="#{dataBean.fetchPeople}" reRender="peopleTableId" />  
      • <rich:dataTable value="#{dataBean.peopleList} var="peopleItem" id="peopleTableId">  
      •     <f:facet name="header"><h:outputText value="People Table" /></f:facet>  
      •     <rich:column>  
      •                 <f:facet name="header">First Name</f:facet>  
      •                 <h:inputText value="#{peopleItem.firstName}"/>  
      •     <h:inputHidden value="#{peopleItem.id}" />  
      •     </rich:column>  
      •     <rich:column>  
      •      <f:facet name="header">Last Name</f:facet>  
      •      <h:inputText value="#{peopleItem.lastName}"/>  
      •     </rich:column>    
      • </rich:dataTable>
      • <h:commandLink value="Save" actionListener="#{dataBean.saveData}" />     



      In my example above initially data table is empty. Clicking on "Populate People Table" link renders 3 rows in the table. However when I click "Save" the bean property dataBean.peopleList does not get set with 3 items.


      I'm using requestScope bean and JSF1.2


      Appreciate if you can help me understand why this happens.

      Also any suggestion to solve above issue.





        • 1. Issue when submitting after AJAX call
          Ilya Sorokoumov Master

          1) h:commandLink should not be inside rich:dataTable

          2) I think that actionListener="dataBean.saveData" should look like actionListener="#{dataBean.saveData}"

          3) You have a requestScope bean and JSF is not supposed to create your objects in list. It just can execute setters for some fields but not a setter for List. That's why you should use a4j:keepAlive tag to keep your bean alive until user is working with the current page. (Or you can put your bean into sessionScope)

          • 2. Issue when submitting after AJAX call
            sudda_1 Newbie

            Points 1 & 2 are valid. They were typo and cut&past errors when I was posting question.


            Point 3 is not very clear regarding JSF not supposed to create objects in list. I found that JSF does know to update items in list in following scenario.


            1. Initialize List in bean constructor (or @PostConstruct init() method).

            2. Use the list in <rich:dataTable > component

            3. Update values on dataTable

            4. Submit Form


            Changes made are updated on List items on the server correctly.

            It's only when some AJAX initiated updates are done on table that they don't get posted.


            So I want to confirm that any AJAX created elements on page(e.g new row in table) does not get set when submitting page.

            • 3. Issue when submitting after AJAX call
              Ilya Sorokoumov Master

              These elements are getting set but if you have requestScope bean it means that they will dissapper just after the ajax call is finished. To save state of bean you should use the options I mentioned.



              - rendering page

              - ajax call add elements to list

              - BREAK POINT 1

              - ajax/non ajax call to set values of objects in list (for insatance object n1,n2,n3 set field x to 'a1','a2','a3')

              - BREAK POINT 2


              So in case of requestScope bean:

              BREAK POINT 1 : list is cleared

              BREAK POINT 2 : jsf can't find these objects n1,n2,n3

              in case of pageScope or sessionScope bean everything works ok.

              • 4. Issue when submitting after AJAX call
                sudda_1 Newbie

                Thank you for the clear explanation.