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] |  |  \- 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] +- org.apache.geronimo.specs:geronimo-jcdi_1.0_spec:jar:1.0:compile
> [INFO] +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
> [INFO] +-
> org.apache.geronimo.specs:geronimo-interceptor_1.1_spec:jar:1.0:compile
> [INFO] +-
> org.apache.geronimo.specs:geronimo-validation_1.0_spec:jar:1.1:compile
> [INFO] +-
> org.apache.geronimo.specs:geronimo-servlet_3.0_spec:jar:1.0:provided
> [INFO] +- org.apache.geronimo.specs:geronimo-el_2.2_spec:jar:1.0.4:provided
> [INFO] +- org.apache.geronimo.specs:geronimo-jsp_2.1_spec:jar:1.0.1:compile
> [INFO] +-
> org.apache.myfaces.buildtools:myfaces-builder-annotations:jar:1.0.9:compile
> [INFO] +- dom4j:dom4j:jar:1.6.1:compile
> [INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
> [INFO] +- org.apache.openwebbeans:openwebbeans-impl:jar:1.2.1:runtime (scope
> not updated to compile)
> [INFO] |  \- org.apache.xbean:xbean-finder-shaded:jar:3.14:runtime
> [INFO] +- org.apache.openwebbeans:openwebbeans-jsf:jar:1.2.1:runtime
> [INFO] +- org.apache.openwebbeans:openwebbeans-web:jar:1.2.1:runtime (scope
> not updated to compile)
> [INFO] +- org.apache.openwebbeans:openwebbeans-spi:jar:1.2.1:runtime
> [INFO] +- org.apache.openwebbeans:openwebbeans-el22:jar:1.2.1:compile
> [INFO] +- org.apache.openwebbeans:openwebbeans-tomcat7:jar:1.2.1:compile
> [INFO] +- org.apache.xbean:xbean-asm4-shaded:jar:3.15:compile
> [INFO] +- org.primefaces-elite:primefaces:jar:4.0.6:compile
> [INFO] +- org.omnifaces:omnifaces:jar:1.6.3:compile
> [INFO] \- javax.servlet:jstl:jar:1.2:compile
>
>
> My faces-config.xml contains :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <faces-config xmlns="http://java.sun.com/xml/ns/javaee";
>               xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance";
>               xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd";
>               version="2.2">
>     <application>
>         <locale-config>
>             <default-locale>fr_FR</default-locale>
>             <supported-locale>fr</supported-locale>
>         </locale-config>
>     </application>
>
>     <factory>
> <exception-handler-factory>fr.senat.faces.exceptions.StdExceptionHandlerFactory</exception-handler-factory>
>     </factory>
>
>     <lifecycle>
> <phase-listener>org.omnifaces.eventlistener.ResetInputAjaxActionListener</phase-listener>
>     </lifecycle>
>  </faces-config>
>
>
> And my web.xml (with security rules stripped...) is :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>      xmlns="http://java.sun.com/xml/ns/javaee";
>      xmlns:web="http://java.sun.com/xml/ns/javaee/webapp_3_0.xsd";
>      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
>      id="senateurs" version="3.0">
>   <display-name>Applications Sénateurs</display-name>
>
>     <context-param>
> <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
> <param-value>/WEB-INF/sens.taglib.xml</param-value>
>       </context-param>
>
>   <welcome-file-list>
>     <welcome-file>accueil.xhtml</welcome-file>
>   </welcome-file-list>
>
>
>   <context-param>
>     <param-name>primefaces.SUBMIT</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>
>   <!-- JSF standard parameters -->
>   <context-param>
>     <param-name>javax.faces.PROJECT_STAGE</param-name>
>     <param-value>Production</param-value>
>   </context-param>
>
>   <context-param>
> <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>   <context-param>
> <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>   <context-param>
>     <description>
>       If this parameter is set to true and the submitted value of a
> component is
>       the empty string, the submitted value will be set to null
>     </description>
> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>   <context-param>
>     <description>State saving method: "client" or "server" (= default)
>     See JSF Specification 2.5.3</description>
> <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
>     <param-value>server</param-value>
>   </context-param>
>
>   <!-- MyFaces specific parameters -->
>   <context-param>
>     <description>Only applicable if state saving method is "server" (=
> default).
>     Defines the amount (default = 20) of the latest views are stored in
> session.</description>
> <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
>     <param-value>20</param-value>
>   </context-param>
>   <context-param>
>     <description>Only applicable if state saving method is "server" (=
> default).
>     If true (default) the state will be serialized to a byte stream before
> it
>     is written to the session.
>     If false the state will not be serialized to a byte
> stream.</description>
> <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
>     <param-value>true</param-value>
>   </context-param>
>   <context-param>
>     <description>Only applicable if state saving method is "server" (=
> default) and if
>     org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
>     If true (default) the serialized state will be compressed before it
>     is written to the session. If false the state will not be
> compressed.</description>
> <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
>     <param-value>true</param-value>
>   </context-param>
>   <context-param>
>     <description>This parameter tells MyFaces if javascript code should be
> allowed in the
>     rendered HTML output.
>     If javascript is allowed, command_link anchors will have javascript code
>     that submits the corresponding form.
>     If javascript is not allowed, the state saving info and nested
> parameters
>     will be added as url parameters.
>     Default: "true"</description>
> <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
>     <param-value>true</param-value>
>   </context-param>
>   <context-param>
> <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
>     <param-value>false</param-value>
>   </context-param>
>   <context-param>
>     <description>If true, rendered HTML code will be formatted, so that it
> is "human readable".
>     i.e. additional line separators and whitespace will be written, that do
> not
>     influence the HTML code.
>     Default: "true"</description>
> <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
>     <param-value>true</param-value>
>   </context-param>
>   <context-param>
>     <description>If true, a javascript function will be rendered that is
> able to restore the
>     former vertical scroll on every request. Convenient feature if you have
> pages
>     with long lists and you do not want the browser page to always jump to
> the top
>     if you trigger a link or button action that stays on the same page.
>     Default: "false"</description>
> <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>
>   <!-- les context-param-s suivants sont tous de recherche de performances
> -->
>   <!-- utilisation de JUEL -->
>   <context-param>
> <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
> <param-value>de.odysseus.el.ExpressionFactoryImpl</param-value>
>   </context-param>
>
>   <!-- utilisation du resolver EL de OpenWebBeans -->
>   <context-param>
> <param-name>org.apache.myfaces.EL_RESOLVER_COMPARATOR</param-name>
> <param-value>org.apache.myfaces.el.unified.OpenWebBeansELResolverComparator</param-value>
>   </context-param>
>
>
>   <!-- desactivation du support des JSP (voir
> https://issues.apache.org/jira/browse/MYFACES-3078 )-->
>   <context-param>
> <param-name>org.apache.myfaces.SUPPORT_JSP</param-name>
>     <param-value>false</param-value>
>   </context-param>
>
>   <!-- ne jamais relire les fichiers XHTML -->
>   <context-param>
> <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
>     <param-value>-1</param-value>
>   </context-param>
>
>   <!-- aucun check de duplicité d'id en prod (voir
> http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_CHECK_ID_PRODUCTION_MODE)
> -->
>   <context-param>
> <param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
>     <param-value>false</param-value>
>   </context-param>
>
>   <!-- voir
> http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_VIEW_UNIQUE_IDS_CACHE_ENABLED
> -->
>   <context-param>
> <param-name>org.apache.myfaces.VIEW_UNIQUE_IDS_CACHE_ENABLED</param-name>
>     <param-value>true</param-value>
>   </context-param>
>
>   <!-- voir
> http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_CACHE_EL_EXPRESSIONS
> -->
>   <context-param>
> <param-name>org.apache.myfaces.CACHE_EL_EXPRESSIONS</param-name>
>     <param-value>strict</param-value>
>   </context-param>
>
>
>
>   <!-- voir
> http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_SAVE_STATE_WITH_VISIT_TREE_ON_PSS
> -->
>   <context-param>
> <param-name>org.apache.myfaces.SAVE_STATE_WITH_VISIT_TREE_ON_PSS</param-name>
>     <param-value>false</param-value>
>   </context-param>
>
>   <resource-ref>
>           <description>Datasource d'authentification</description>
>           <res-ref-name>jdbc/authSen</res-ref-name>
>           <res-type>javax.sql.DataSource</res-type>
>           <res-auth>Container</res-auth>
>   </resource-ref>
>
>
>   <!-- theme de l'interface PrimeFaces -->
>   <!-- <context-param> -->
>   <!--   <param-name>primefaces.THEME</param-name> -->
>   <!--   <param-value>humanity</param-value> -->
>   <!-- </context-param> -->
>
>   <!-- Listener for OpenWebBeans configuration -->
>   <listener>
>     <listener-class>
>           net.sf.ehcache.constructs.web.ShutdownListener
>     </listener-class>
>   </listener>
>   <listener>
>     <listener-class>
>       org.apache.webbeans.servlet.WebBeansConfigurationListener
>     </listener-class>
>   </listener>
>
>   <!-- Listener for Senat / Hibernate -->
>   <listener>
>     <listener-class>
>       fr.senat.faces.listeners.SenatSessionListener
>     </listener-class>
>   </listener>
>
>   <filter>
> <filter-name>HibernateUserFromPrincipalFilter</filter-name>
> <filter-class>fr.senat.faces.filters.HibernateUserFromPrincipalFilter</filter-class>
>   </filter>
>
>   <filter-mapping>
> <filter-name>HibernateUserFromPrincipalFilter</filter-name>
>     <url-pattern>*.xhtml</url-pattern>
>   </filter-mapping>
>
>   <filter>
> <filter-name>HibernateSessionConversationFilter</filter-name>
> <filter-class>fr.senat.faces.filters.HibernateSessionConversationFilter</filter-class>
>   </filter>
>
>   <filter-mapping>
> <filter-name>HibernateSessionConversationFilter</filter-name>
>     <url-pattern>*.xhtml</url-pattern>
>   </filter-mapping>
>
>     <servlet>
>         <description>Affiche une photo de l'annuaire</description>
>         <display-name>PhotoViewer</display-name>
>         <servlet-name>PhotoViewer</servlet-name>
> <servlet-class>senat.applications.photos.PhotoViewer</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>PhotoViewer</servlet-name>
>         <url-pattern>/PhotoViewer</url-pattern>
>     </servlet-mapping>
>
>   <servlet>
>     <servlet-name>Faces Servlet</servlet-name>
> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
>     <load-on-startup>1</load-on-startup>
>   </servlet>
>   <servlet-mapping>
>     <servlet-name>Faces Servlet</servlet-name>
>     <url-pattern>*.xhtml</url-pattern>
>   </servlet-mapping>
>
>   <session-config>
>     <session-timeout>15</session-timeout>
>   </session-config>
>
>   <error-page>
>       <error-code>403</error-code>
> <location>/unrestricted/acces_refuse.html</location>
>   </error-page>
>
>   <error-page>
>       <error-code>404</error-code>
> <location>/unrestricted/page_non_trouvee.html</location>
>   </error-page>
>
>   <!-- JSF lève cette exception sur une page non trouvée -->
>   <error-page>
>     <error-code>500</error-code>
> <location>/unrestricted/erreur_interne.xhtml</location>
>   </error-page>
> </web-app>
>
> |
> | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> |
>

Reply via email to