3 Replies Latest reply on Apr 5, 2011 8:19 AM by lvdberg

    Seam & Delegation

    lovelyliatroim
      Hi Guys,
         Im just playing with seam and trying to get a feel for it but ive hit a stumbling block.

      Im playing around with pagination and i dont like having to dump all the pagination variables that i have in every component that needs pagination. (Maybe i dont need to but from the examples ive seen)

      Here is my setup


      @Name("statusManager")
      @Scope(ScopeType.CONVERSATION)
      public class StatusManager implements Serializable, PagingListener {

           @Out
           private PagingHandler pagingHandler = PagingHandler.getInstance(this);

           public void searchByState() {
                Query query = entityManager.createQuery(queryStr);
                dataModel = QueryHelper.getResultList(query,pagingHandler);
              }

           @Override
           public String changePage() {
                searchByState();
                return null;
           }

      }

      @Name("pagingHandler")
      @Scope(ScopeType.CONVERSATION)
      public class PagingHandler {

           private int pageNo = 1;
           private int pageSize = 5;
           private boolean morePagesAvailable = true;
           private PagingListener listener = null;
      ......

      On the front end then i have just this

      <custom:pager controller="#{statusManager.pagingHandler}" />


      Now the problem with the above is with the call back, when "next" or "previous" is called, it calls the paging handler instance which calls the StatusManager.changePage but the entity manager is null when chnageState is called and it bombs out (obviously because seam hasnt injected the entityManager) because the request has gone to the paging handler instance.

      Im completely new to seam and have played around with setting the paging handler instance to be @Out and also made it a component but to no avail.(This is where i feel im going wrong, incorrectly annotating but im just hacking at the moment to get it to work, i should read up more but hey ;) )

      Is it possible to do what i want to do here??


      Appreciate any help or pointers in the right direction,
      JB
        • 1. Re: Seam & Delegation
          lvdberg

          Hi,


          I would be happy to help, you, but I would recommend that you first get a basic idea on the workings of Seam before you start playing and/or hacking.


          The Seam component EntityQuery has excellent - built-in - support for pagination, so under normal circumstances there is no need whatsoever to build such functionality yourself. Seam MUST handle the management of components, so at the moment you create with new, or with a factory method, Seam doesn't handle such instance, so in- and outjecting won't work.





          • Get the full doc and examples of Seam

          • buy the Seam in Action book.




          Leo


           

          • 2. Re: Seam & Delegation
            lovelyliatroim

            Hi Leo,
               Im more interested in the interaction of the components between each other. Dont get hung up by the fact that it is pagination im more interested in how the call back works or would work in seam.


            I realise from your comments (Thanks) that this wont work


             @Out
             private PagingHandler pagingHandler = PagingHandler.getInstance(this);
            



            As you said seam must manage the components to it should possibly look like something like this


            @In @Out
             private PagingHandler pagingHandler ;
            



            What im stuck on is how the injection of the pagingListener in PagingHandler from seam would work?? I dont see it in the docs. 


            Is the above even possible in seam??
            Cheers,
            JB

            • 3. Re: Seam & Delegation
              lvdberg

              Hi,


              you can create components statically in Seam more or less like Spring does. You define a component in componenst.xml and provides its name and the class it should use and (optionally) a scope. Instance variables can be set as tags inside the component tag.



              If you want Seam to handle the creation with annotations, you need the In-annotation with the attribute create


              @In(create=true)



              , which takes care of creating an instance. You can also put an AutoCreate annotation on a component.


              Leo