8 Replies Latest reply on Feb 20, 2007 7:05 PM by vk101

    EL enhancements

      Do the EL enhancements only work when used as the action attribute of a link? I ask because I got a parse exception when I tried to use #{entityHome.myMethod(var)} as plain text in an h:column, where var is the loop variable of the dataTable.

      Is the EL enhancement not supposed to work here, or should I keep looking for where I might have made a mistake?


      Also, I'm confused as to when methods need to have a "get" prefixed to their name when the name is specified in EL. For example, for what I described above (entityHome.myMethod), would the entityHome need a method named myMethod, or getMyMethod?

        • 1. Re: EL enhancements

          Below is the log of the exception. Also, I have the following in my faces-config.xml:

          <application>
           ...
           <view-handler>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</view-handler>
          </application>


          javax.el.ELException: Error Parsing: #{compHome.done(x.id)}
           at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:140)
           at com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:157)
           at com.sun.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:201)
           at com.sun.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:74)
           at org.jboss.seam.ui.facelet.SeamExpressionFactory.createValueExpression(SeamExpressionFactory.java:105)
           at com.sun.facelets.el.ELText$ELTextVariable.apply(ELText.java:161)
           at com.sun.facelets.el.ELText$ELTextComposite.apply(ELText.java:142)
           at com.sun.facelets.compiler.TextInstruction.apply(TextInstruction.java:56)
           at com.sun.facelets.compiler.UIInstructionHandler.apply(UIInstructionHandler.java:85)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.ui.DefineHandler.apply(DefineHandler.java:58)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:128)
           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:306)
           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:279)
           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
           at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:143)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
          Caused by: com.sun.el.parser.ParseException: Encountered "(" at line 1, column 20.
          Was expecting one of:
           "}" ...
           "." ...
           "[" ...
           ">" ...
           "gt" ...
           "<" ...
           "lt" ...
           ">=" ...
           "ge" ...
           "<=" ...
           "le" ...
           "==" ...
           "eq" ...
           "!=" ...
           "ne" ...
           "&&" ...
           "and" ...
           "||" ...
           "or" ...
           "*" ...
           "+" ...
           "-" ...
           "?" ...
           "/" ...
           "div" ...
           "%" ...
           "mod" ...
          
           at com.sun.el.parser.ELParser.generateParseException(ELParser.java:1651)
           at com.sun.el.parser.ELParser.jj_consume_token(ELParser.java:1531)
           at com.sun.el.parser.ELParser.DeferredExpression(ELParser.java:134)
           at com.sun.el.parser.ELParser.CompositeExpression(ELParser.java:61)
           at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:103)
           at com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:157)
           at com.sun.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:201)
           at com.sun.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:74)
           at org.jboss.seam.ui.facelet.SeamExpressionFactory.createValueExpression(SeamExpressionFactory.java:105)
           at com.sun.facelets.el.ELText$ELTextVariable.apply(ELText.java:161)
           at com.sun.facelets.el.ELText$ELTextComposite.apply(ELText.java:142)
           at com.sun.facelets.compiler.TextInstruction.apply(TextInstruction.java:56)
           at com.sun.facelets.compiler.UIInstructionHandler.apply(UIInstructionHandler.java:85)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.ui.DefineHandler.apply(DefineHandler.java:58)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:128)
           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:306)
           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:279)
           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)


          • 2. Re: EL enhancements
            pmuir

            As mentioned in the docs you can only use the EL enhancement on method bindings, not value bindings (i.e. a get/is/set)

            • 3. Re: EL enhancements

              What is the recommended method of executing a query for each line in a DataModel or list of entities on a page upon each load?

              I was thinking I could pass in the loop variable to a method that would go and execute a query. Since that's not possible, what should I do - I know how to use DataModel for doing things once you've selected an entity, but not how to do something for every entity, with regards to a list.

              Is there a good example of this I could check in the Seam examples?

              • 4. Re: EL enhancements
                baz

                You wrote

                tried to use #{entityHome.myMethod(var)} as plain text

                So your el uses value binding.
                When you want to really call a method you have to use a button or link where you have an action or actionlistener attribute.
                For example: s:link action="#{entityHome.myMethod(var)}"

                • 5. Re: EL enhancements

                  Right, but that would only be evaluated when I click the link, whereas I would like the value to be shown when the list page is shown.

                  For example, in a list of entities I'd like to show next to it the result of a query (i.e. that value isn't stored as a property of the entity, but is evaluated as a result of a query).

                  I can't see how to get them all to display on the list page.

                  • 6. Re: EL enhancements
                    pmuir

                     

                    "lightbulb432" wrote:
                    What is the recommended method of executing a query for each line in a DataModel or list of entities on a page upon each load?


                    You can't do it like this. You would have to preprocess the list in your factory method. Normally you can avoid doing this by getting the datamodel right.

                    • 7. Re: EL enhancements
                      pmuir

                       

                      "lightbulb432" wrote:
                      For example, in a list of entities I'd like to show next to it the result of a query (i.e. that value isn't stored as a property of the entity, but is evaluated as a result of a query).


                      You could use the map hack for this (look at Seam's isUserInRole) or preprocess as I mentioned above.

                      BTW it would really be much easier to help if you actually posted example code of what you were trying to do.

                      • 8. Re: EL enhancements

                        Here's the type of thing I'm trying to do. The point is that there are a list of "favorites", and within that list I want to specially mark those favorites of the logged in user.

                        But of course, the enhanced EL expression I have in the view doesn't work. It seems like the most intuitive way to do it, but I guess I have to look for another option.

                        Hopefully you can advise as to what I can do here. Thanks.

                        @DataModel
                        private List favorites;
                        
                        @Factory
                        public void getFavorites() {
                         favorites = entityManager.createQuery("...").getResultList();
                        }
                        
                        public String getStatus(int id) {
                         for (Favorite f : member.getFavorites()) {
                         if (member.getFavorite().getId() == id) return "Your Favorite";
                         }
                         return "Not Your Favorite";
                        }


                        <h:dataTable value="#{favorites}" var="fave">
                         <h:column>
                         #{fave.name}
                         </h:column>
                         <h:column>
                         #{entityHome.status(fave.id)}
                         </h:column>
                        </h:dataTable>