10 Replies Latest reply on Oct 11, 2010 3:12 PM by notify

    Accessing @DataModel in POJO

    notify
      Have returned to my Seam App after some months away.

      Have had no trouble populating my List using a method in my EJB (3.x) as DataModel

      @DataModel
      private List <Postcards> postcardsList;

      and interating through it in the XHTL and displaying it using

      <rich:dataTable id="dataTableYourPhotographs" value="#{postcardsList}" var="postcards" columns="5" >

      However I need to access it in POJO, but it always 'null', though I can see in the EJB when I delete an item it has the a number of Entities in the list.

      In the POJO method called from the XHTML page "postcardsList" is always null.

      What have I missed?

      Thanks.








        • 1. Re: Accessing @DataModel in POJO
          lvdberg

          Hi,


          I assume the EJB is a stateful bean, which by default has a conversation scope, while a normal bean has a event scope. I cant see the rest of your code, but it is most ceratinly the cause of your problem.


          Leo

          • 2. Re: Accessing @DataModel in POJO
            notify

            Leo,


            Yes it's a Stateful EJB, but the scope is set to session.


            @Stateful
            @Name(postcardBean)
            @Interceptors(SeamInterceptor.class)
            @JndiName(ejb/PostcardRemote)
            @Scope(ScopeType.SESSION)
            public class PostcardBean implements PostcardRemote, NOTiFYPiNPOiNTConstants, NOTiFYPiNPOiNTSQL {




            • 3. Re: Accessing @DataModel in POJO
              lvdberg

              Hi,


              this explains why it always works. The bean is created when you start the session and stays in memory until the user signs-off. How is the list of entities created ? and have you done the same for the POJO )session scope)?


              Leo


              P.S:  please send in additional code because I am not a medium.

              • 4. Re: Accessing @DataModel in POJO
                notify

                How is the list of entities created ? and have you done the same for the POJO )session scope)?


                The Enities are created here;


                @SuppressWarnings({ "unchecked" })
                @Factory("postcardsList")  
                public final List <Postcards> getPostCardsByDomain() {
                          Query query = entityManager.createQuery(GET_POSTCARDS_BY_DOMAIN);
                          query.setParameter(ONE, this.getDomain(credentials.getUsername()));
                          
                              this.postcardsList = query.getResultList();
                              log.info(">>>>> getPostCardsByDomain postcardsList.size = " + postcardsList.size());
                
                              return this.postcardsList;
                }
                



                and stored in the list;


                @DataModel
                @Out (required = false)
                private List <Postcards> postcardsList;
                



                I am trying to inject the postcardsList (the DataModel) into the POJO.


                The POJO is referenced in the faces-config.xml with a scope of session;


                <managed-bean>
                        <managed-bean-name>fileUploadBean</managed-bean-name>
                        <managed-bean-class>com.notifypinpoint.pojos.FileUploadBean</managed-bean-class>
                        <managed-bean-scope>session</managed-bean-scope>
                </managed-bean>
                

                • 5. Re: Accessing @DataModel in POJO
                  lvdberg

                  Ok,


                  that makes sense now. You're not using a Seam managed bean. Try making the POJO a seam.bean by adding the name- and scope annotations and try again.


                  Leo

                  • 6. Re: Accessing @DataModel in POJO
                    notify

                    Try making the POJO a seam.bean by adding the name- and scope annotations and try again.


                    I already had;


                    @Name("fileUploadBean")
                    @Scope(ScopeType.SESSION)
                    public class FileUploadBean implements NOTiFYPiNPOiNTConstants {
                    


                    • 7. Re: Accessing @DataModel in POJO
                      lvdberg

                      Hi,


                      If you have the POJO as a Seam bean, why are you defining it again in faces-config.xml ?


                      Leo

                      • 8. Re: Accessing @DataModel in POJO
                        notify

                        If you have the POJO as a Seam bean, why are you defining it again in faces-config.xml ?


                        Leo,


                        I realised whilst I was out I was mixing a POJO with a Seam Bean. Thanks for highlighting it to me.


                        My EAR won't deploy now as it says;


                        ERROR [[/]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
                        java.lang.RuntimeException: Could not create Component: imagesBean
                        




                        Do I have registers any Seam Componets to use a Seam Bean?


                        Thanks for your help.

                        • 9. Re: Accessing @DataModel in POJO
                          lvdberg

                          Hi,


                          you must follow the basic rules for Seam , meaning add configurations to web.xml and  - if you use facelets - the view handler setting in faces config and also the seam.properties file inside META-INF (or other jars). The seam documentation contains a clear explanation how to configure a basic seam environment and seam-gen can help you kick-start your new application.


                          Leo

                          • 10. Re: Accessing @DataModel in POJO
                            notify

                            you must follow the basic rules for Seam , meaning add configurations to web.xml and  - if you use facelets - the view handler setting in faces config and also the seam.properties file inside META-INF (or other jars). The seam documentation contains a clear explanation how to configure a basic seam environment and seam-gen can help you kick-start your new application.


                            Cleaned up my JBoss directories etc and all is well and the Entity is being injected.


                            Thanks for your patience and suggestions.