3 Replies Latest reply on Apr 8, 2006 12:12 PM by Markus Dahm

    @Name and abstract classes

    Markus Dahm Novice

      Hi,

      I have an abstract Entity class named Vertragspartner which has
      several descendants and annotate it with @Name("vertragspartner")

      Somewhere else I have a session bean which references that name.
      I want to bind a concrete class to this field.

       @In(value = "vp")
       @Out(value = "vp", required = false)
       @Valid
       private Vertragspartner _vertragspartner;
      


      However running this code causes an exception:

      javax.faces.el.EvaluationException: Cannot get value for expression '#{vertragspartner.name}'
       at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:397)
       at javax.faces.component.UIOutput.getValue(UIOutput.java:75)
       at org.apache.myfaces.renderkit.RendererUtils.getStringValue(RendererUtils.java:225)
       at org.apache.myfaces.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:131)
       at org.apache.myfaces.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:49)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
       at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:349)
       at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:253)
       at org.apache.jsp.registerVertragspartner_jsp._jspx_meth_h_inputText_0(org.apache.jsp.registerVertragspartner_jsp:229)
       at org.apache.jsp.registerVertragspartner_jsp._jspx_meth_h_form_0(org.apache.jsp.registerVertragspartner_jsp:172)
       at org.apache.jsp.registerVertragspartner_jsp._jspx_meth_c_view_0(org.apache.jsp.registerVertragspartner_jsp:138)
       at org.apache.jsp.registerVertragspartner_jsp._jspService(org.apache.jsp.registerVertragspartner_jsp:83)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
       at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
       at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
       at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
       at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
       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.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.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
       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:868)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
       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: java.lang.IllegalArgumentException: value found for In attribute has the wrong type: vertragspartner
       at org.jboss.seam.Component.getInstance(Component.java:1054)
       at org.jboss.seam.Component.getInstance(Component.java:1027)
       at org.jboss.seam.jsf.SeamVariableResolver.resolveVariable(SeamVariableResolver.java:43)
       at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(ValueBindingImpl.java:569)
       at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
       at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:140)
       at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:378)
       ... 46 more
      2006-04-05 14:39:02,156 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/iv].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.faces.FacesException: Cannot get value for expression '#{vertragspartner.name}'
       at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:421)
       at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
       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.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.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
       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:868)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
       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: org.apache.jasper.JasperException: Cannot get value for expression '#{vertragspartner.name}'
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
       at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
       at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
       at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:415)
       ... 22 more
      


      Looking into that code with the debugger I found out that the component
      "vertragspartner" is not bound to the abstract class but to some of
      the concrete classes (not always the same as it seems).

      This causes the type clash since the concrete subclasses are not
      assignment compatible with each other of course. I got around this
      problem by using a wrapper class which is bound to the name and
      holds the instance.

      But surely there is either a good reason or a bug fix for that problem...

      Cheers
      Markus

        • 1. Re: @Name and abstract classes
          Uhyon Chung Newbie

          Why would you @name abstract classes? I thought the idea of @Name was to have Seam create an instance (in the JSF namespace) of the object, but abstract classes cannot be instantiated! Or maybe I didn't quite read your posting correctly...

          • 2. Re: @Name and abstract classes
            Gavin King Master

             

            "uhyonc" wrote:
            Why would you @name abstract classes? I thought the idea of @Name was to have Seam create an instance (in the JSF namespace) of the object, but abstract classes cannot be instantiated!


            Right.

            • 3. Re: @Name and abstract classes
              Markus Dahm Novice

              Hi,

              the intention was to have a component to which I can bind
              any subclass of the abstract class. Which didn't work for the
              listed reasons.

              The concrete use case is:

              The sub classes all have the same fields, thus the form/JSP is also
              the same, just the instance used is different. I have a drop down box
              for the user to select the kind of instance he wants to create.
              The attached action reads this argument and acts as some kind
              of factory to create the right object.

              I wanted to use one symbolic name for any of these instance
              in the form editor action (see above the @In and @Out).
              Otherwise I would have had to annotate all the subclasses, and
              make a distinction between all of them.

              Maybe there is already a better solution for this problem, which I
              just didn't see....


              Cheers
              Markus