4 Replies Latest reply on Jan 7, 2008 3:55 AM by kummer

    Calling the same method on different beans from the same act

    kummer

      I am trying to reuse a facelets file in various use cases with a different stateful session bean managing each use case.

      In order to do that the beans outject themselves as "manager". For example:

      @Stateful @Name("auditOrderManager") public class AuditOrderManager {
       @Out AuditOrderManager manager = this;
       @In private FacesMessages facesMessages;
       @Begin(nested=true) public void doSelectOrder() {...}
      }
      


      and

      @Stateful @Name("cancelOrderManager") public class CancelOrderManager {
       @Out CancelOrderManager manager = this;
       @In private FacesMessages facesMessages;
       @Begin(nested=true) public void doSelectOrder() {...}
      }
      


      In an action attribute a call is made to a method, which is present on all these different managers.

      <h:column>
       <f:facet name="header">Ta-Nr</f:facet>
       <s:link value="-"
       action="#{manager.doSelectOrder}"/>
      </h:column>
      


      The doSelectMethod of the correct manager does get called, but appearantly the annotations have no effect. The facesMessages component is not injected and the conversation doesn't nest. Giving a concrete component name in the action solves that problem but precludes reuse. Since the same fragment is used all over the application I would rather not have a spearate instance of it for each manager.

      Is there a way to achieve reuse in this case?

        • 1. Re: Calling the same method on different beans from the same
          pmuir

          You outject this, which isn't managed. The normal approach here is to pass the correct manager name into the xhtml fragment

          <ui:include ...>
           <ui:param name="manager" value="#{auditOrderManager}" />
          </ui:include>


          • 2. Re: Calling the same method on different beans from the same
            kummer

            I followed your suggestion except that I changed the name of the param from manager to orderManager in the both the param tag and the included file. The page displays correctly but invoking an action via

            <s:link action="#{orderManager.doSelectOrder}"/>
            


            triggers the following exception

            Exception during request processing:
            Caused by javax.el.PropertyNotFoundException with message: "Target Unreachable, identifier 'orderManager' resolved to null"
            
            org.jboss.el.parser.AstValue.getTarget(AstValue.java:38)
            org.jboss.el.parser.AstValue.invoke(AstValue.java:95)
            org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
            org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
            org.jboss.seam.navigation.Pages.callAction(Pages.java:634)
            org.jboss.seam.navigation.Pages.preRender(Pages.java:289)
            org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:544)
            org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:455)
            org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:146)
            org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:116)
            com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
            com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            lu.deka.servlets.LoggedInFilter.doFilter(LoggedInFilter.java:56)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Thread.java:619)
            



            Any ides?


            • 3. Re: Calling the same method on different beans from the same
              pmuir

              Post the template and the fragment so we can clearly see what is going on.

              • 4. Re: Calling the same method on different beans from the same
                kummer

                Here are the files (cut down, but still showing the error).

                The application template:

                <?xml version="1.0" encoding="ISO-8859-1"?>
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:s="http://jboss.com/products/seam/taglib"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:h="http://java.sun.com/jsf/html">
                 <head>
                 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                 </head>
                 <body>
                 <ui:insert name="content"/>
                 </body>
                </html>
                


                The including XHTML:

                <?xml version="1.0" encoding="ISO-8859-1"?>
                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:s="http://jboss.com/products/seam/taglib"
                 xmlns:c="http://java.sun.com/jstl/core">
                
                
                 <ui:define name="content">
                 <c:set var="orderBaseDisabled" value="#{true}"/>
                 <ui:include src="/orderBase.xhtml"/>
                 <s:div rendered="#{manager.orderTableAspect.rendered.orderTable}">
                 <ui:include src="/orderTable.xhtml">
                 <ui:param name="orderManager" value="#{auditOrderManager}"/>
                 </ui:include>
                 <s:button
                 value="Abbrechen"
                 action="#{auditOrderManager.doCancel}" styleClass="Button"/>
                 </s:div>
                
                 </ui:define>
                
                </ui:composition>
                



                The included XHTML:

                <?xml version="1.0" encoding="ISO-8859-1"?>
                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:c="http://java.sun.com/jstl/core"
                 xmlns:s="http://jboss.com/products/seam/taglib">
                 <p>test output orderManager: #{orderManager}</p>
                 <s:div id="orderTable" rendered="#{orderManager.orderTableAspect.rendered.orderTable}">
                 <h:dataTable var="order" value="#{orders}">
                 <h:column><f:facet name="header">Ta-Nr</f:facet><s:link value="-" action="#{orderManager.doSelectOrder}"/></h:column>
                 </h:dataTable>
                 </s:div>
                
                </ui:composition>
                


                The line

                <p>test output orderManager: #{orderManager}</p>


                in the included file produces

                test output orderManager: AuditOrderManagerBean:an3e3x-aslh4y-fb2c7qhq-1-fb4rpdvp-12