6 Replies Latest reply on Jun 20, 2007 12:16 PM by Pete Muir

    Method binding with context variable as a parameter - parser

    Daniel Kane Novice

      Hello

      In example 1.23 listing of Seam documentation I see the code :

      <h:dataTable value="#{hotels}" var="hot" rendered="#{hotels.rowCount>0}">
       <h:column>
       <f:facet name="header">Name</f:facet>
       #{hot.name}
       </h:column>
       <h:column>
       <f:facet name="header">Address</f:facet>
       #{hot.address}
       </h:column>
       <h:column>
       <f:facet name="header">City, State</f:facet>
       #{hot.city}, #{hot.state}, #{hot.country}
       </h:column>
       <h:column>
       <f:facet name="header">Zip</f:facet>
       #{hot.zip}
       </h:column>
       <h:column>
       <f:facet name="header">Action</f:facet>
       <s:link value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
       </h:column>
       </h:dataTable>
      


      And, the comment :

      Also notice that we use a method binding with a parameter: #{hotelBooking.selectHotel(hot)}. This is not possible in the standard Unified EL, but Seam provides an extension to the EL that lets you use parameters on any method binding expression


      My code is :
      <h:dataTable id="partsTbl" value="#{parts}" var="part" rendered="#{parts.rowCount>0}">
       <h:column>
       ......
       </h:column>
       <h:column>
       <s:button action="#{cart.addPart(part,1)}" value="Add to Cart"/>
       </h:column>
       </h:dataTable>
      


      And, I am getting the exception :



      com.sun.facelets.tag.TagAttributeException: /parts.xhtml @66,68 action="#{cart.addPart(part,1)}" Error Parsing: #{cart.addPart(part,1)}
       at com.sun.facelets.tag.TagAttribute.getMethodExpression(TagAttribute.java:144)
       at com.sun.facelets.tag.jsf.ActionSourceRule$ActionMapper.applyMetadata(ActionSourceRule.java:50)
       at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
       at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
       at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
       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.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.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
       at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
       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)
       at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
       at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:503)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:546)
       at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:229)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
       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.MultipartFilter.doFilter(MultipartFilter.java:79)
       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.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.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.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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       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:799)
      Caused by: javax.el.ELException: Error Parsing: #{cart.addPart(part,1)}
       at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:160)
       at com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:177)
       at com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:228)
       at com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:70)
       at com.sun.facelets.tag.TagAttribute.getMethodExpression(TagAttribute.java:141)
       ... 67 more
      Caused by: com.sun.el.parser.ParseException: Encountered "(" at line 1, column 15.
      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:128)
       ... 71 more



      What am I doing wrong ?

        • 1. Re: Method binding with context variable as a parameter - pa
          Pete Muir Master

          You need to be using SeamFaceletViewHandler - check the faces-config.xml of the booking example (assuming you are on Seam 1.2)

          • 2. Re: Method binding with context variable as a parameter - pa
            Daniel Kane Novice

            Thanks a lot Pete, it was the case. Solved.

            • 3. Re: Method binding with context variable as a parameter - pa
              Daniel Kane Novice

              Still one problem, though .

              When I call a method with single argument (argument is entity bean) everything works well :

              JSF code

              <s:button action="#{cart.addPart(part)}" value="Add to Cart"/>


              Java code
              public void addPart(PartCMP part)
              {
               cartOrder.addPosition(part, 1);
              }



              But when I use 2 arguments, I am getting IllegalArgumentException :

              JSF code
              <s:button action="#{cart.addPart(part,1)}" value="Add to Cart"/>


              Java code
              public void addPart(PartCMP part, int quantity)
              {
               cartOrder.addPosition(part, quantity);
              }


              Is SEAM facelet handler able to process calls with multiple arguments ?

              • 4. Re: Method binding with context variable as a parameter - pa
                Pete Muir Master

                What's the exception (full stack trace please). N.B. The EL in 1.3 is much more powerful than that in 1.2

                • 5. Re: Method binding with context variable as a parameter - pa
                  Daniel Kane Novice

                   

                  20:12:18,375 ERROR [SeamPhaseListener] uncaught exception
                  javax.faces.el.EvaluationException: Exception while invoking expression #{cart.addPart}
                   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:165)
                   at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
                   at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
                   at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:148)
                   at org.jboss.seam.core.Pages.callAction(Pages.java:499)
                   at org.jboss.seam.core.Pages.enterPage(Pages.java:282)
                   at org.jboss.seam.jsf.AbstractSeamPhaseListener.enterPage(AbstractSeamPhaseListener.java:276)
                   at org.jboss.seam.jsf.AbstractSeamPhaseListener.beforeRender(AbstractSeamPhaseListener.java:214)
                   at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:56)
                   at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:70)
                   at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:373)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
                   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.MultipartFilter.doFilter(MultipartFilter.java:79)
                   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.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.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.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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
                   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:799)
                  Caused by:
                  java.lang.IllegalArgumentException
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                   at java.lang.reflect.Method.invoke(Method.java:615)
                   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
                   ... 42 more
                  20:12:18,406 ERROR [DebugPageHandler] redirecting to debug page
                  java.lang.IllegalArgumentException
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                   at java.lang.reflect.Method.invoke(Method.java:615)
                   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
                   at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
                   at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
                   at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:148)
                   at org.jboss.seam.core.Pages.callAction(Pages.java:499)
                   at org.jboss.seam.core.Pages.enterPage(Pages.java:282)
                   at org.jboss.seam.jsf.AbstractSeamPhaseListener.enterPage(AbstractSeamPhaseListener.java:276)
                   at org.jboss.seam.jsf.AbstractSeamPhaseListener.beforeRender(AbstractSeamPhaseListener.java:214)
                   at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:56)
                   at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:70)
                   at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:373)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
                   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.MultipartFilter.doFilter(MultipartFilter.java:79)
                   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.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.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.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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
                   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:799)


                  • 6. Re: Method binding with context variable as a parameter - pa
                    Pete Muir Master

                    Have you tried using an Integer rather than an int? That exception is being thrown because the method cannot be invoked - it's not a syntax exception from the el enhancement