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

    Weld 2.0 under Tomcat 7

    Please NoSpam Newbie



      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


      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





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

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










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











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


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

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


        <Resource name="BeanManager"





        <!-- enable injection into Servlet -->

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









      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.




      Now to the major problem.




      public class CheckoutFlow implements Serializable {


          private static final long serialVersionUID = 1L;




          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")






              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();





      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.



        • 1. Re: Weld 2.0 under Tomcat 7
          Martin Kouba Master



          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.

          • 3. Re: Weld 2.0 under Tomcat 7
            Martin Kouba Master

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

            • 4. Re: Weld 2.0 under Tomcat 7
              Please NoSpam Newbie

              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?



              <flow-call id="callcheckoutFlow">






                  <value>param1 joinFlow value</value>




                  <value>param2 joinFlow value</value>





              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



              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-



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

              • 5. Re: Weld 2.0 under Tomcat 7
                Martin Kouba Master

                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 :-)