8 Replies Latest reply on Jul 9, 2009 5:17 PM by wachtda.scsi.gmx.ch

    Factory, Datamodel and back Button

    wachtda.scsi.gmx.ch

      hello together


      i've read the existing back button threads without any success for my problem.
      in my seam app i have the problem, that the page displayed upon browser back button doesn't seem's to be rendered correctly.
      that means, the page is displayed and all components except the datatable component are rendered with correct data.


      the datatable component is empty, until i invoce the method manually to fill the datatable.
      if i manually call the method to fill the datatable, the page is rendered with the expected values!
      (even the paginator points to the correct page)


      has this problem something to do that my datable is backed to a @datamodel which is provided trough a @factory?

      see simplified examples. (the pages.xml has no specific settings in it, cause I use a s:link for redirecting)


      thank you for helping, i don't get the clue!

      ;-(


      page:



      <h:dataTable id="alerts" var="map" value="#{myAlerts}">
         <h:column>
            <f:facet name="header">
               <h:outputText value="#{messages.f_device}" />
            </f:facet>
            <s:link action="#{deviceAction.selectDevice}" view="/device.xhtml"
             value="#{map.key.device.model.description} (#{map.key.device.networkAddress})"
             title="#{map.key.device.description}">
               <f:param name="deviceID" value="#{map.key.device.id}" />
            </s:link>
         </h:column>
      </h:dataTable>



      bean 1:



      @Stateful
      @Name("alertAction")
      @Scope(ScopeType.SESSION)
      public class AlertOverviewActionImpl implements AlertOverviewAction
      {
         ...
         @DataModel
         private LinkedHashMap<Alert, String> myAlerts;
         ...
      
         @Factory("myAlerts")
         public void allAlerts()
         {   
            ...loading data...
         }
      ...
      }
      



      bean 2:



      @Stateful
      @Name("deviceAction")
      @Scope(ScopeType.EVENT)
      public class DeviceActionImpl implements DeviceAction
      {
         ...
         public void selectDevice()
         {   
            ...selecting data...
         }
      ...
      }
      









        • 1. Re: Factory, Datamodel and back Button
          lvdberg

          Have you tried to put Bean 1 in another scopetype ? Default behaviour is to Outject the datamodel to the same scopetype as the owning component, so basically myAlerts is in Session scope.


          Leo

          • 2. Re: Factory, Datamodel and back Button
            lvdberg

            Additional,


            I also think that your Factory is not called, because the Datamodel (in session scope) already contains a value.



            Leo

            • 3. Re: Factory, Datamodel and back Button
              wachtda.scsi.gmx.ch

              hy,


              yes the myAlerts is in session scope!

              but if i come back to my alertOverview, why it doesn't display the datatable with the datamodel?
              needs the factory to get called, in order to the datatable can display the datamodel?

              • 4. Re: Factory, Datamodel and back Button
                lvdberg

                The factory annotation is used for methods which should be called when the associated value (in your case myAlerts) has no value.


                And I think that because it possibly already has a value (because of being in the session scope) , the method will not be called.


                Leo

                • 5. Re: Factory, Datamodel and back Button
                  rccs

                  Hi Leo.
                       
                  I have a datamodel that is loaded with a select to a table (category), and shown on a page (listarCategoria.xhtml), on the same page I do a search on the table (category), the datamodel is updated but only for view in the page (listarCategoria.xhtml), my problem is that when I choose one of the categories of result of the search, the datamodelseleccion is loaded with the object of the datamodel initial.
                  How can I update the datamodel?


                  Help me please.


                  ¡¡¡¡¡¡Excuse my English is not very good.!!!!!

                  • 6. Re: Factory, Datamodel and back Button
                    wachtda.scsi.gmx.ch

                    Hi Leo, sorry for my late answer!
                    (Since I was abroad I couldn't answer to your posting)


                    Perhaps I don't understand the @Datamodel the right way.
                    If I define a Collection with @Datamodel in a SFSB, does it not preserve its value trough the session?
                    I tried it, with some logs on the size of my datamodel and it appears NULL if I come back with the back button.


                    What do I have to do, that if the user comes back with the backbutton that the datamodel keep it's value?

                    Thanks for helping

                    • 7. Re: Factory, Datamodel and back Button
                      wachtda.scsi.gmx.ch

                      Found the problem/solution!


                      The problems caused by the rich:datascroller which i use for my table.

                      The solution (maybe someone can tell me if this is a proper solution..?):



                      1. Added var to bean which stores the datascrollers page index

                      2. Bound the datascroller to this var:
                        page="#{alertOverviewAction.pageIndex}"


                      3. Added action to the bean to listen to (from pages.xml)

                      4. Bound the datascroller to this action:
                        action="#{alertOverviewAction.dsAction}"


                      5. Added pages.xml entry for handling this (ajax) action:
                        ...<navigation from-action="#{alertOverviewAction.dsAction}"><redirect view-id="/MY_PAGE.XHTML" /></navigation>...




                      Now the back button works very well, and displays the latest position before link redirection.

                      Further informations available here and here.


                      Thanks for helping out

                      Cheers Daniel

                      • 8. Re: Factory, Datamodel and back Button
                        wachtda.scsi.gmx.ch

                        One thing I forgot to mention.
                        The solution which I used (and is posted in different threads and FAQ) results in a page request.

                        Will say the ajax request will be discarded for this solution.


                        If you have a page on which you must have an ajax request the only solution i found is to rerender the component upon page
                        load:


                        <a:jsFunction name="reloadAjaxComponents reRender="componentsToReload" />



                        and then call the jsFunction with for example a


                        <body onload="reloadAjaxComponents()">



                        (More information about this solution here)


                        Im not very happy with this solution, but sadly I found not any better one.

                        Perhaps someone else has a better solution for this scenario!??

                        Thanks for any hints...