8 Replies Latest reply on Sep 10, 2007 4:41 AM by jamesjmp

    problem using entityqueries

      hello,
      This issue is somehow strange, so I provide you with the related code to make my explanation clear.
      I´ve defined this entity-query in my components.xml file.

      <framework:entity-query name="RstReportTemplate2"
       ejbql="select rstReport from RstReport rstReport"
       order="code">
       </framework:entity-query>


      If I use it directly from a view xhtml file it works ok. For example
       </rich:dataTable>
       <rich:dataTable id="RstReportTemplate2"
       var="rstReport"
       value="#{RstReportTemplate2.resultList}"
       rendered="#{not empty RstReportTemplate2.resultList}">
       <h:column>
       #{rstReport.code}
       </h:column>
       </rich:dataTable>


      I want to use it from a POJO. I´ve a POJO that uses this query this way:

      @Name("RstReportTemp")
      public class RstReportTemplate {
      
       @In("#{RstReportTemplate2.resultList}") List<RstReport> rstRepTemplates;
      
       public RstReportTemplate() {
       }
      
       public void processTemplate() {
       Iterator<RstReport> rstReportTemp = rstRepTemplates.iterator();
       if (rstRepTemplates != null) {
       while (rstReportTemp.hasNext()) {
       // business logic code
       }
      
       }else {
       System.out.println("THERE ARE --NO-- RECORDS MATCHING RstReportTemplate2");
       }
       }
      
      }
      


      When invoking to this POJO from a pojoview.page.xml with an action it works fine
      <action execute="#{RstReportTemp.processTemplate}"/>


      Now, here is my problem. I want to invoke that method, RstReportTemp.processTemplate, from the wire method of a POJOHome.
      I´m doing it this way:
      @Name("rstReportHome")
      public class RstReportHome extends EntityHome<RstReport> {
      
       public void wire() {
       ...
       RstReportTemplate repTemp = new RstReportTemplate();
       repTemp.processTemplate(rep);
       ..
       }
      ...}

      This time the query doesn´t return any value, in fact the resulting List rstRepTemplates is null.

      I don´t understand why the same query (with no restrictions) works fine when used directly from a view or from a POJO which is invoked by an execute of a .page.xml, but doesn´t behave the same way when it is used from a POJO which has been invoked from a different POJO.
      I don´t want to have my business logic code in the POJOHome java class, that´s why I´m using another one and invoking from the wire method.
      thanks in advance,
      Jaime

        • 1. Re: problem using entityqueries
          pmuir

           

          RstReportTemplate repTemp = new RstReportTemplate();


          is not the correct way to instantiate Seam components. Use @In (RTM)

          • 2. Re: problem using entityqueries

            Thank you Pete, but what do you mean with "RTM"?
            I´ve tried with this:

            @In RstReportTemplate repTemp;

            and then in the wire method...
            repTemp = new RstReportTemplate();
             repTemp.processTemplate();


            This way I have this error:
            11:47:59,484 ERROR [DebugPageHandler] redirecting to debug page
            org.jboss.seam.RequiredException: In attribute requires non-null value: rstReportHome.repTemp

            I´m sure that I´m not doing it properly. could you please explain the solution a bit further?
            thank you!
            Jaime

            • 3. Re: problem using entityqueries
              ohad

              try @In(create = true)
              you don't need to new it()

              • 4. Re: problem using entityqueries

                Thank you, but the same error keeps on happenning


                14:31:45,765 ERROR [DebugPageHandler] redirecting to debug page
                org.jboss.seam.RequiredException: In attribute requires non-null value: rstReportHome.repTemp


                The code is now:

                @Name("rstReportHome")
                public class RstReportHome extends EntityHome<RstReport> {
                ...
                 @In(create = true)
                 RstReportTemplate repTemp;
                ...
                public void wire() {
                ..
                repTemp.processTemplate(rep);
                ...


                This behaviour, with create=true, doesn´t seem to conform to what is said in the seam reference

                @In
                Specifies that a component attribute is to be injected from a context variable at the beginning of each component
                invocation. If the context variable is null, an exception will be thrown
                @In(create=true)
                Specifies that a component attribute is to be injected from a context variable at the beginning of each component
                invocation. If the context variable is null, an instance of the component is instantiated by Seam.


                I guess I´m still doing something wrong, but I´ve no idea what it is. ;-(



                • 5. Re: problem using entityqueries
                  stephen.friedrich

                  If you don't specify a component name in the value attribute of the @In annotation the name is taken from the variable declaration, which would be "repTemp" in your case which is wrong.

                  Try
                  @In(value="RstReportTemplate", create=true)
                  RstReportTemplate repTemp;

                  • 6. Re: problem using entityqueries
                    stephen.friedrich

                    Grr, must of course be value="RstReportTemp"

                    • 7. Re: problem using entityqueries
                      pmuir

                      RTM is the politer version of RTFM

                      • 8. Re: problem using entityqueries

                        Thank you for your assistance. All works fine now. I do appreciate the help of this forum.
                        Pete I´ve read the manual but the first time you´re tackling a new technology it´s difficult to remember and assimilate all you´ve read and tried. Hope my asking this question to this forum hasn´t bothered you. You guys are making a great achievement with this technology and I really want SEAM to succeed.