8 Replies Latest reply on Nov 7, 2008 5:49 PM by joblini

    getRestrictions() in Seam 2.1

    twhitehead.twhiteheadjm.hotmail.com

      I am trying out 2.1.0.GA and have noticed that restrictions are now ValueExpressions.
      I changed my code as follows


      @Override
      public List<String> getRestrictions() {          
           return Arrays.asList(RESTRICTIONS);
      }



      changes to


      @Override
      public List<ValueExpression> getRestrictions() {
           setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
           return super.getRestrictions();
      }



      but now it is throwing a null pointer:


      Caused by: java.lang.NullPointerException
           at org.jboss.seam.framework.Query.getRenderedEjbql(Query.java:252)
           at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:175)
           at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:73)
           at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:65)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)



      I cant find any examples in 2.1 that overide the getRestrictions even though that is what used to be generated by seam-gen. What is the new way of doing it if any?


      And incidentally, why cant I use the version number 2.1.0.GA as a tag for the thread? Surely it would make sense if your issue is specific to a version?
           

        • 1. Re: getRestrictions() in Seam 2.1
          dan.j.allen

          You should be setting your restriction strings in the constructor of the class (or the @Create method). Generally it is bad practice to perform logic in the getter method, which is why I changed the templates for seam-gen.

          • 2. Re: getRestrictions() in Seam 2.1
            dan.j.allen

            And incidentally, why cant I use the version number 2.1.0.GA as a tag for the thread? Surely it would make sense if your issue is specific to a version?


            Start a new thread for this question and perhaps even consider filing a JIRA report if you get positive feedback.

            • 3. Re: getRestrictions() in Seam 2.1
              twhitehead.twhiteheadjm.hotmail.com

              Thank you for the advice. I created a project with seam-gen to see how it does it and now my class is like this:


              @Name("incomeList")
              public class IncomeList extends EntityQuery<Income> {     
                   private static final String[] RESTRICTIONS = { 
                        "income.aircraft.site.oid=#{currentSite.oid}",
                        "income.aircraft.oid=#{current.aircraftOid}", 
                        "income.incomeType.oid=#{current.incomeTypeOid}",          
                   };
                   private static final String EJBQL = "select income from Income income";
              
                   public IncomeList() {
                        setEjbql(EJBQL);
                        setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                        setMaxResults(25);
                   }
              }



              But it still throws the same null pointer exception.
              This is code that works in 2.0.3.CR1


              I dont think any of the examples that ship with seam extend EntityQuery, so it is necessary to use seam-gen to get an idea of how it should be used.
              The project I created with seam-gen does work.

              • 4. Re: getRestrictions() in Seam 2.1
                loebb01

                Hi Dan,


                since the @Create annotation cannot be used in EntityQueries:


                Which is the recommeded way creating restrictions using injected components?


                At the time the constructor is called, all injections are null.


                Thanks, Daniel

                • 5. Re: getRestrictions() in Seam 2.1
                  dan.j.allen

                  What makes you think that you cannot use @Create for an EntityQuery? Any Seam component can take advantage of @Create.

                  • 6. Re: getRestrictions() in Seam 2.1
                    loebb01

                    Hi Dan,


                    since the @Create annotation is already used in org.jboss.seam.framework.Query.validate(), the server tells the following on deployment:


                    java.lang.IllegalStateException: component has two @Create methods: <component name>


                    So, from my point of view, the only way is to overwrite the validate() method. But that does not rreally makes sense for me.


                    Do you see any alternatives?


                    Bye, Daniel

                    • 7. Re: getRestrictions() in Seam 2.1
                      accless

                      Dan Allen wrote on Oct 23, 2008 17:02:



                      And incidentally, why cant I use the version number 2.1.0.GA as a tag for the thread? Surely it would make sense if your issue is specific to a version?


                      Start a new thread for this question and perhaps even consider filing a JIRA report if you get positive feedback.



                      The @Create Annotation is not introduced in Seam 2.1, it already exists in Seam 2.0.


                      The validation against the availability of a set ejb-String at creation time of the component, does not make much sense to me...  My work around was to copy the src-code of EntityQuery and Query, in order to be able to modify both of them.


                      The classes I create are subclassed from my modified EntityQuery and Query Object. This gives me more flexibility and freedom in modifying restrictions and validation which are set by default when u use these classes



                      greetings

                      • 8. Re: getRestrictions() in Seam 2.1
                        joblini

                        It would be helpful to include this information regarding setRestrictionExpressionStrings in the migration21.txt file.