7 Replies Latest reply on Nov 3, 2007 7:22 AM by Sven Mueller

    getter problem

    Sven Mueller Newbie

      hi,

      my problem is a well known problem but nonetheless i'm wondering how to do it right..maybe one of you can help me with this issue:

      i have a datatable which uses an extended datamodel (similar to this example http://wiki.apache.org/myfaces/WorkingWithLargeTables) to cope with large amount of data. the problem is that @datamodel doesn't work with that kind of object so i need another way how to avoid that my buisness logic (database calls) in the getter are executed several times per request.

      class:

      @Scope(ScopeType.SESSION)
      @Name("component")
      public class Component {
      
       public getDataModel() {
       // calls to database etc.
       }
      
      }


      xhtml:

      <rich:datatable id="dataTable" value="#{component.dataModel}" var="product" >

      ...

      </h:datatable>



      the data of the table should be refreshed with every request, for example if the user hits the refresh button of the browser. how can i remove my buisness logic from the getter? is there a way to use @factory (and @datamodel)?

      thanks in advance,
      sven

      ps: i'm not using hibernate...




        • 1. Re: getter problem
          Sven Mueller Newbie

          hi,

          i thougt one of you could maybe give me a hint because it is a common problem. is it possible to solve this issue without using @dataModel?

          thanx,
          sven

          • 2. Re: getter problem
            Pete Muir Master

            @Factory/@Create. Or, better yet, use an EntityQuery which supports paging data natively.

            • 3. Re: getter problem
              Sven Mueller Newbie

              thank you pete, now i'm using the @factory annotation.

              for pagination i'm using rich:datascroller and a dataTable component-binding (as recommended in the doc: http://docs.jboss.com/seam/2.0.0.CR1/reference/en/html_single/#d0e5034)



              @In(create = true)
              // dataTable binding
              protected Binding binding;

              @Factory(scope=ScopeType.EVENT)
              public DataModel getItems() {

              // in this method i'm using the current dataTable index (dataTable.getFirst()) and pagesize (dateTable.getRows) to get the items for the selected page

              }





              <rich:dataTable id="dataTable" binding="#{binding.dataTable}" value="#{items}">

              ..
              </rich:dataTable>


              the problem with that is, that i need the current index of the datatable within the factory method to fetch the items for selected page. but at the time the factory method is executed (after restore view phase) the method binding.dataTable.getFirst() returns the old value because it isn't initialized yet.

              how can i get the current index of the dataTable (if datascroller is used) so that i'm able to fetch the next page items in the factory method? any ideas?

              cheers,
              sven

              • 4. Re: getter problem
                Pete Muir Master

                I don't entirely understand why you are trying to do. Are you trying to lazy load data based on where the section of the datatable you are loading?

                • 5. Re: getter problem
                  Sven Mueller Newbie

                  i only want to fetch those items which are shown on the current active page. therefore i need the actual index of the datatable. but by the time the factory method is executed the method binding.datatable.getFirst() always returns 0. my question is how can i get the current index of my datatable so that i can use it to build the query in the factory method.

                  thank you for your suppot,
                  sven

                  ps: i can't use an entityquery because i haven't an entitymanager at all. i'm building a webapp on top of a third party ecommerce plattform which provides its own api with a sql like qery language.

                  • 6. Re: getter problem
                    Sven Mueller Newbie

                    there has to be a solution or at least a workaround for this issue..or am i doing something abnormal? how do you handle pagination (loading only those items which are currently needed for the view) with the datascroller component?

                    cheers,
                    sven

                    • 7. Re: getter problem
                      Sven Mueller Newbie

                      anyone else using rich:datascroller with large datasets?