Flow scope navigation to start page does not work

别来无恙 提交于 2019-12-12 14:21:57

问题


It is not so much a question, more of a note. With Glassfish4, in a JEE7 application I tried to use the flow scope using programmatic flow definition (java class annotated with @Produces @FlowDefinition).

I navigated to the start page of the flow with a h:commandButton (just as it is done in the JEE7 tutorial example https://svn.java.net/svn/javaeetutorial~svn/trunk/examples/web/jsf/checkout-module. When I pressed the button it stayed on the same page, where the button was, instead of going to the flow's start page.

After many hours of suffering, I realized that the problem is in the beans.xml, in my beans.xml I had this:

bean-discovery-mode="annotated"

which is the recommended setting according to the documentation (http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/beans_1_1.xsd). When I changed this to

bean-discovery-mode="all"

it started to work.

Somehow CDI does not recognize the flow definition as an annotated class. I tried to make it a @Named class, or a @ApplicationScoped class, but non of these helped. I don't know if it is the intended behavior, or a bug.

Hope it saves a few ours to someone.


回答1:


This is related to how CDI detects bean archives. When bean-discovery-mode="annotated", only classes annotated with bean defining annotations are picked up by CDI; note that @Named and @FlowScoped aren't on that list.

Because of this, as you've documented here, using Flow annotations requires bean-discovery-mode="all" to be set.

There's a spec issue open to discuss if this is a desired behavior.




回答2:


Thank you!

Of course you can always fallback to using an XML declaration for your view. Such as creating a file example/example-flow.xml with contents such as

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
          xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
          http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
  <flow-definition id="example">
    <flow-return id="actionId" >
        <from-outcome>#{somebean.returnValue}</from-outcome>                
    </flow-return>
  </flow-definition>
</faces-config>


来源:https://stackoverflow.com/questions/22178375/flow-scope-navigation-to-start-page-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!