2 Replies Latest reply on Jul 4, 2007 2:54 PM by Glenn Marcus

    how to extend EntityQuery

    Glenn Marcus Newbie

      Seam 1.2.1
      Jboss 4.0.5

      I have extended EntityQuery:

      @Name("predictionList")
      @Scope(CONVERSATION)
      public class PredictionList extends EntityQuery
      {
       private static final long serialVersionUID = -28849438634100838L;
      
       @In(required=true, create=true)
       private PredictionFilter predictionFilter;
      
       @Override
       public String getEjbql() {
       return "select p from Prediction p";
       }
      
       @Override
       public List<String> getRestrictions()
       {
       System.out.println("getRestrictions() called. PredictionFilter:" + predictionFilter);
      
       ArrayList<String> restrictions = new ArrayList<String>(0);
      
       if (predictionFilter.getFilterChoice().equals(PredictionFilter.FilterChoice.ALL))
       {
       return restrictions;
       }
      
       if (predictionFilter.getFilterChoice().equals(PredictionFilter.FilterChoice.FEATURED))
       {
       restrictions.add("p.featured=true");
       return restrictions;
       }
      
       if (predictionFilter.getFilterChoice().equals(PredictionFilter.FilterChoice.EDITORSPICKS))
       {
       restrictions.add("p.editorspick=true");
       return restrictions;
       }
      
       return restrictions;
      
       }
      
      ...
      
      


      When I use predictionList in my view:
      <h:outputText class="nopredictions" value="No predictions to display" rendered="#{empty predictionList.resultList}"/>
      <h:dataTable styleclass="predictions" value="#{predictionList.resultList}" var="pre" rendered="#{not empty predictionList.resultList}">
      ...
      


      I get the following exception:
      javax.faces.el.EvaluationException: /layout/predictions.xhtml @8,118 rendered="#{empty predictionList.resultList}": com.mystuff.fresh.domain.PredictionList_$$_javassist_304
       at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
       at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:822)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:241)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
       at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:101)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:221)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:75)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:213)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: Bean: com.mystuff.fresh.domain.PredictionList_$$_javassist_304, property: resultList
       at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:404)
       at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:71)
       at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
       at com.sun.el.parser.AstValue.getValue(AstValue.java:125)
       at com.sun.el.parser.AstEmpty.getValue(AstEmpty.java:49)
       at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
       ... 44 more
      Caused by: java.lang.reflect.InvocationTargetException
       at sun.reflect.GeneratedMethodAccessor7810.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:400)
       ... 51 more
      Caused by: java.lang.IllegalArgumentException: there should be exactly one value binding in a restriction: p.featured=true
       at org.jboss.seam.framework.Query.parseEjbql(Query.java:145)
       at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:100)
       at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:41)
       at sun.reflect.GeneratedMethodAccessor7811.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:34)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:32)
       at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
       at org.jboss.seam.interceptors.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
       at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
       at com.mystuff.fresh.domain.PredictionList_$$_javassist_304.getResultList(PredictionList_$$_javassist_304.java)
       ... 55 more
      


      Are restrictions the right way to set the where clause on a query?



        • 1. Re: how to extend EntityQuery
          fhh Expert

          The error has nothing to do with extensind EntityQuery.

          there should be exactly one value binding in a restriction: p.featured=true
          


          You must have exactly one value binding in your restriction. Try using
          p.features=#{true}
          


          Regards

          Felix


          • 2. Re: how to extend EntityQuery
            Glenn Marcus Newbie

             

            "fhh" wrote:
            You must have exactly one value binding in your restriction. Try using
            p.features=#{true}
            



            Thanks for the reply. What you say makes sense.
            I needed to get something up and running so I put the logic in the getEjbql() method for now.
            I will go back and try it with restrictions for future classes.

            Thanks again,
            Glenn