问题
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