5 Replies Latest reply on Jul 12, 2013 7:58 AM by mkouba

    Weld 2.0 under Tomcat 7

    sjhgo82.da

      Hello,

       

      I am testing Faces Flow Scopes of JSF 2.2. Therefore I can run the example application checkout-module from the javaee 7 turorial Sect. 16.3

      http://docs.oracle.com/javaee/7/tutorial/doc/jsf-configure003.htm#sthref1026

      under Glassfish 4.0 final without any problems.

       

      Now I tried to run the example under Apache Tomcat with Weld. The whole Eclipse-Project is attached. I did all as told from the weld documentation in chapter 18.3

      http://docs.jboss.org/weld/reference/2.0.1.Final/en-US/html/environments.html#d0e5324

       

      WEB-INF/web.xml:

      {code:xml}

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app id="FlowScopeTest" version="3.0"

              xmlns="http://java.sun.com/xml/ns/javaee"

              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

        ...

        <listener>

          <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>

        </listener>

        <resource-env-ref>

          <description>Object factory for the CDI Bean Manager</description>

          <resource-env-ref-name>BeanManager</resource-env-ref-name>

          <resource-env-ref-type>

            javax.enterprise.inject.spi.BeanManager

          </resource-env-ref-type>

        </resource-env-ref>

      </web-app>

      {code}

       

      META-INF/context.xml:

      {code:xml}

      <?xml version="1.0" encoding="UTF-8"?>

      <Context>

        <!-- disables storage of sessions across restarts -->

        <!-- <Manager pathname=""/> -->

       

        <Resource name="BeanManager"

                  auth="Container"

                  type="javax.enterprise.inject.spi.BeanManager"

                  factory="org.jboss.weld.resources.ManagerObjectFactory"/>

       

        <!-- enable injection into Servlet -->

        <!-- <Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener"/> -->

       

        <!--

        <WatchedResource>WEB-INF/web.xml</WatchedResource>

        <WatchedResource>META-INF/context.xml</WatchedResource>

        -->

      </Context>

      {code}

       

      Under WEB-INF/lib I have cdi-api.jar, weld-servlet.jar, and javax.faces-2.2.0.jar . Please note, I use Weld 2.0.0 Final as 2.0.1 Final does not operate in this setting: javax.el, logging, extra libraries needed, etc.

       

      project.png

       

      Now to the major problem.

       

      src/javaeetutorial.checkoutmodule/CheckoutFlow.java

      {code}

      public class CheckoutFlow implements Serializable {

       

          private static final long serialVersionUID = 1L;

       

          @Produces

          @FlowDefinition

          public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {

              System.out.println("----HelloHello----: currently not executed -> bug?");

       

              String flowId = "checkoutFlow";

              flowBuilder.id("", flowId);

              flowBuilder.viewNode(flowId, "/" + flowId + "/" + flowId + ".xhtml")

                  .markAsStartNode();

       

              flowBuilder.returnNode("returnFromCheckoutFlow")

                  .fromOutcome("#{checkoutFlowBean.returnValue}");

       

              flowBuilder.inboundParameter("param1FromJoinFlow", "#{flowScope.param1Value}");

              flowBuilder.inboundParameter("param2FromJoinFlow", "#{flowScope.param2Value}");

       

              flowBuilder.flowCallNode("calljoin").flowReference("", "joinFlow")

                  .outboundParameter("param1FromCheckoutFlow", "#{checkoutFlowBean.name}")

                  .outboundParameter("param2FromCheckoutFlow", "#{checkoutFlowBean.city}");

              return flowBuilder.getFlow();

          }

      }

      {code}

       

      The method defineFlow to programmatically define the flow scope is never executed, i.e., System.out.println(...) is never executed. GlassFish does this without problems while starting the webapp. Of course, the application later complains about the missing scope.

      Is this a bug, do I make something wrong?

       

      Please help. Many thanx.

       

      Chris

        • 1. Re: Weld 2.0 under Tomcat 7
          mkouba

          Hi,

           

          I checked the WAR you provided and it's actually a JSF impl (Mojarra) issue. The problem is in the way Mojarra detects the CDI container - it simply tries to obtain an instance of BeanManager from JNDI by looking up the name java:comp/BeanManager. This is what the CDI spec declares. However in Tomcat and Jetty it's not possible to bind the BeanManager to that name, so the BeanManager is available at java:comp/env/BeanManager (see also Weld documentation). And back to the issue: Mojarra does not detect CDI container and does not invoke the flow definition producer. The fix is simple, just add one more JNDI lookup to handle servlet containers - I'll raise an issue.

          • 2. Re: Weld 2.0 under Tomcat 7
            mkouba
            • 3. Re: Weld 2.0 under Tomcat 7
              mkouba

              Please could you verify the provided patch attached to JAVASERVERFACES-2922?

              • 4. Re: Weld 2.0 under Tomcat 7
                sjhgo82.da

                The patch seems to fix that, ie, using javax.faces.jar as provided in Mojarra's bug data base does work.

                Many thanks @Martin!

                 

                OT: Do you know why Eclipse does not validate the xml-Code of joinFlow-flow.xml?

                 

                {code:xml}

                <flow-call id="callcheckoutFlow">

                  <flow-reference>

                    <flow-id>checkoutFlow</flow-id>

                  </flow-reference>

                  <outbound-parameter>

                    <name>param1FromJoinFlow</name>

                    <value>param1 joinFlow value</value>

                  </outbound-parameter>

                  <outbound-parameter>

                    <name>param2FromJoinFlow</name>

                    <value>param2 joinFlow value</value>

                  </outbound-parameter>

                </flow-call>

                {code}

                 

                Eclipse tells  me

                 

                cvc-complex-type.2.4.a: Invalid content was found starting with element 'flow-call'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":inbound-parameter}' is

                expected.

                 

                in line 1 of the above snippet and

                 

                Multiple annotations found at this line:

                    - cvc-complex-type.2.2: Element 'value' must have no element [children], and the value must be valid.

                    - cvc-pattern-valid: Value 'param1 joinFlow value' is not facet-valid with respect to pattern '#\{.*\}' for type 'faces-config-el-

                     expressionType'.

                 

                in lines 7 and 11. This is original code from the JEE 7 Tutorial.

                • 5. Re: Weld 2.0 under Tomcat 7
                  mkouba

                  Good to hear it works! Re XML - I have no idea. Anyway it's not a Weld-related question, so try Eclipse and JSF forums :-)