@FlowScoped, @Named and @ManagedBean

2014-02-10 Thread l.pe...@senat.fr

Dear all,

I am starting to really use JSF 2.2. I am trying to use Faces Flows. I 
am starting with a very simple flow, whose name is flow1.


So, under src/main/webapp, I have a flow1 directory containing

flow1-flow.xml
flow1.xhtml
flow1b.xhtml

flow1-flow.xml contains :

?xml version=1.0 encoding=UTF-8?
faces-config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://xmlns.jcp.org/xml/ns/javaee'
xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd'

version='2.2' 
flow-definition id=flow1
flow-return id=returnFromFlow1
from-outcome/accueil/from-outcome
/flow-return
/flow-definition
/faces-config


With such a simple config, using conventions would be a better choice 
than configuration, but I plan to add more things to it... :-)


I use a @FlowScoped bean declared this way :

@Named
@FlowScoped(flow1)
public class MinintFileContext implements Serializable {


}

and it does not work. I have the following exception :

javax.servlet.ServletException: javax.servlet.ServletException: 
javax.el.ELException: 
javax.enterprise.context.ContextNotActiveException: WebBeans context 
with scope type annotation @FlowScoped does not exist within current thread



To make it work, I have to use @ManagedBean instead of @Named.

My first question is : I do not understand why... In my (obviously 
wrong) understanding, @Named was a super-set of CDI-managed beans, 
including @ManagedBean-s.


Another question...

I am using PrimeFaces p:menubar . I noticed that I can not use /flow1 
as the outcome of a menuitem


Ex : p:menuitem value=Blah blah blah outcome=/flow1 /

I have to use

p:menuitem value=Blah blah blah outcome=/flow1/flow1 /

Why ? This might be a PF-specific question.


Finally, I am failing to use the flow-return configuration.

I tried

p:commandButton value=Terminer action=returnFromFlow1/

and

h:commandButton value=Terminer action=returnFromFlow1/

But it just does not work.

So, I tried to change the config to

flow-return id=returnFromFlow1
from-outcome#{minintFileContext.returnValue}/from-outcome
/flow-return

and added a

public String getReturnValue() {
return /accueil;
}

method to he MinintFileContext bean, but it does not work better.

Any idea ?

Thanks in advance



I have the following JSF-related or generic dependencies (I mean that I 
remove in-house dependencies from the following tree) :
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ 
faces-dependencies ---

[INFO] fr.senat:faces-dependencies:jar:4.0.0-SNAPSHOT
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- org.apache.tomcat:tomcat-catalina:jar:7.0.47:provided
[INFO] |  +- org.apache.tomcat:tomcat-servlet-api:jar:7.0.47:provided
[INFO] |  +- org.apache.tomcat:tomcat-juli:jar:7.0.47:provided
[INFO] |  +- org.apache.tomcat:tomcat-annotations-api:jar:7.0.47:provided
[INFO] |  +- org.apache.tomcat:tomcat-api:jar:7.0.47:provided
[INFO] |  \- org.apache.tomcat:tomcat-util:jar:7.0.47:provided
[INFO] +- org.apache.myfaces.core:myfaces-api:jar:2.2.0:compile
[INFO] +- org.apache.myfaces.core:myfaces-impl:jar:2.2.0:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.3:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  \- commons-digester:commons-digester:jar:1.8:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jsf20-module-api:jar:1.0.5:compile
[INFO] |  \- 
org.apache.myfaces.extensions.cdi.core:myfaces-extcdi-core-api:jar:1.0.5:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jsf20-module-impl:jar:1.0.5:runtime
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jpa1-module-api:jar:1.0.5:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-jpa1-module-impl:jar:1.0.5:runtime
[INFO] |  \- 
org.apache.myfaces.extensions.cdi.core:myfaces-extcdi-core-impl:jar:1.0.5:runtime
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-bv1-module-api:jar:1.0.5:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-bv1-module-impl:jar:1.0.5:runtime
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-scripting-module-api:jar:1.0.5:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-scripting-module-impl:jar:1.0.5:runtime
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-message-module-api:jar:1.0.5:compile
[INFO] +- 
org.apache.myfaces.extensions.cdi.modules:myfaces-extcdi-message-module-impl:jar:1.0.5:runtime
[INFO] +- 
org.apache.geronimo.specs:geronimo-atinject_1.0_spec:jar:1.0:compile

[INFO] +- 

AUTO: Geetika Srivastava is out of the office (returning Fri 05/23/2014)

2014-02-10 Thread Geetika Srivastava

I am out of the office from Sat 02/08/2014 until Fri 05/23/2014.





Note: This is an automated response to your message  @FlowScoped, @Named
and @ManagedBean sent on 02/10/2014 22:26:00.

This is the only notification you will receive while this person is away.

=-=-=
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you





Re: @FlowScoped, @Named and @ManagedBean

2014-02-10 Thread Leonardo Uribe
Hi

2014-02-10 11:56 GMT-05:00 l.pe...@senat.fr l.pe...@senat.fr:
 Dear all,

 I am starting to really use JSF 2.2. I am trying to use Faces Flows. I am
 starting with a very simple flow, whose name is flow1.

 So, under src/main/webapp, I have a flow1 directory containing

 flow1-flow.xml
 flow1.xhtml
 flow1b.xhtml

 flow1-flow.xml contains :

 ?xml version=1.0 encoding=UTF-8?
 faces-config
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xmlns='http://xmlns.jcp.org/xml/ns/javaee'
 xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee
 http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd'
 version='2.2' 
 flow-definition id=flow1
 flow-return id=returnFromFlow1
 from-outcome/accueil/from-outcome
 /flow-return
 /flow-definition
 /faces-config


 With such a simple config, using conventions would be a better choice than
 configuration, but I plan to add more things to it... :-)

 I use a @FlowScoped bean declared this way :

 @Named
 @FlowScoped(flow1)
 public class MinintFileContext implements Serializable {

 
 }

 and it does not work. I have the following exception :

 javax.servlet.ServletException: javax.servlet.ServletException:
 javax.el.ELException: javax.enterprise.context.ContextNotActiveException:
 WebBeans context with scope type annotation @FlowScoped does not exist
 within current thread


 To make it work, I have to use @ManagedBean instead of @Named.

 My first question is : I do not understand why... In my (obviously wrong)
 understanding, @Named was a super-set of CDI-managed beans, including
 @ManagedBean-s.



@FlowScoped annotation is for CDI only, so it will not work for JSF
managed beans. In your case, I believe the bean is instantiated but it
is not stored in any context, so once is created is discarded, giving
the impression that the bean is working but it is not.

In MyFaces it is possible to create a custom flow scope annotation for
other containers that works just like @FlowScoped, implementing
org.apache.myfaces.spi.FacesFlowProvider SPI interface. You are
already in CDI, so you don't need to bother about that.

I have seen @Named annotation working with Spring, so it is not
something specific for CDI, but @FlowScoped depends of CDI API.

 Another question...

 I am using PrimeFaces p:menubar . I noticed that I can not use /flow1 as
 the outcome of a menuitem

 Ex : p:menuitem value=Blah blah blah outcome=/flow1 /

 I have to use

 p:menuitem value=Blah blah blah outcome=/flow1/flow1 /

 Why ? This might be a PF-specific question.


Try in this way:

p:menuitem value=Blah blah blah outcome=flow1 /

If you put /flow1 as outcome, the navigation algorithm will
interpret this as a normal navigation to a page (/flow1.xhtml), so the
flow scope will not be activated and the bean will not be instantiated
correctly. It should work without any changes in primefaces, because
the outcome should be calculated using
ConfigurableNavigationHandler.getNavigationCase(...).


 Finally, I am failing to use the flow-return configuration.

 I tried

 p:commandButton value=Terminer action=returnFromFlow1/

 and

 h:commandButton value=Terminer action=returnFromFlow1/

 But it just does not work.

 So, I tried to change the config to

 flow-return id=returnFromFlow1
 from-outcome#{minintFileContext.returnValue}/from-outcome
 /flow-return

 and added a

 public String getReturnValue() {
 return /accueil;
 }

 method to he MinintFileContext bean, but it does not work better.

 Any idea ?


Try it again, maybe the reason is that it seems you are inside the
flow but it is not. You can check if you are in the flow using
facesContext.getApplication().getFlowHandler().isActive(...).

regards,

Leonardo Uribe

 Thanks in advance



 I have the following JSF-related or generic dependencies (I mean that I
 remove in-house dependencies from the following tree) :
 [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @
 faces-dependencies ---
 [INFO] fr.senat:faces-dependencies:jar:4.0.0-SNAPSHOT
 [INFO] +- commons-lang:commons-lang:jar:2.6:compile
 [INFO] +- org.apache.commons:commons-lang3:jar:3.1:compile
 [INFO] +- org.apache.tomcat:tomcat-catalina:jar:7.0.47:provided
 [INFO] |  +- org.apache.tomcat:tomcat-servlet-api:jar:7.0.47:provided
 [INFO] |  +- org.apache.tomcat:tomcat-juli:jar:7.0.47:provided
 [INFO] |  +- org.apache.tomcat:tomcat-annotations-api:jar:7.0.47:provided
 [INFO] |  +- org.apache.tomcat:tomcat-api:jar:7.0.47:provided
 [INFO] |  \- org.apache.tomcat:tomcat-util:jar:7.0.47:provided
 [INFO] +- org.apache.myfaces.core:myfaces-api:jar:2.2.0:compile
 [INFO] +- org.apache.myfaces.core:myfaces-impl:jar:2.2.0:compile
 [INFO] |  +- commons-collections:commons-collections:jar:3.2:compile
 [INFO] |  +- commons-codec:commons-codec:jar:1.3:compile
 [INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
 [INFO] |  |  \-