6 Replies Latest reply on Jan 29, 2008 3:57 AM by Vladimir Kovalyuk

    FacesContext is null in Identity.initCredentialsFromCookie

    Jacob Liu Newbie

      Hi. I'm working on a seam application (with Seam 2.0 GA) and now I want to use the "rememberMe" feature. The application is deployed to tomcat 6.0 and I'm using myfaces 1.2.

      The problem is that the "rememberMe" feature of Seam never works for me and I tried to debug into the codes and fount that when Identity.initCredentialsFromCookie() was invoked, after the first line of this method:

      FacesContext ctx = FacesContext.getCurrentInstance();
      

      ctx is null.

      Can anybody give me some hints?

      This is my components.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:persistence="http://jboss.com/products/seam/persistence"
       xmlns:transaction="http://jboss.com/products/seam/transaction"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
      
       <core:manager conversation-timeout="120000"
       concurrent-request-timeout="500" conversation-id-parameter="cid" />
       <core:init jndi-pattern="#{ejbName}/local" debug="false" />
      
       <transaction:entity-transaction entity-manager="#{em}" />
      
       <persistence:entity-manager-factory name="myDatabase" />
      
      
       <persistence:managed-persistence-context name="em"
       auto-create="true" entity-manager-factory="#{myDatabase}" />
      
       <security:identity
       authenticate-method="#{authenticator.authenticate}" />
      
       <event type="org.jboss.seam.notLoggedIn">
       <action execute="#{redirect.captureCurrentView}" />
       </event>
      
      
       <event type="org.jboss.seam.postAuthenticate">
       <action execute="#{redirect.returnToCapturedView}" />
       </event>
      
      </components>
      


      This is my faces-config.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
      
       <application>
      
       <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
       <locale-config>
       <default-locale>en</default-locale>
       <supported-locale>en</supported-locale>
      
       </locale-config>
       </application>
      
      
      </faces-config>
      


      This is my web.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
       <!-- Seam -->
      
       <listener>
       <listener-class>
       org.jboss.seam.servlet.SeamListener
       </listener-class>
       </listener>
      
       <filter>
       <filter-name>Seam Filter</filter-name>
       <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
       </filter>
      
       <filter>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <filter-class>
       org.apache.myfaces.webapp.filter.ExtensionsFilter
       </filter-class>
       </filter>
       <filter>
       <display-name>Ajax4jsf Filter</display-name>
       <filter-name>ajax4jsf</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       </filter>
      
       <filter-mapping>
       <filter-name>ajax4jsf</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       </filter-mapping>
      
       <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages -->
       <filter-mapping>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
       <servlet-name>Faces Servlet</servlet-name>
       </filter-mapping>
      
       <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
       <filter-mapping>
       <filter-name>MyFacesExtensionsFilter</filter-name>
       <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
       </filter-mapping>
      
      
      
       <filter-mapping>
       <filter-name>Seam Filter</filter-name>
       <url-pattern>/*</url-pattern>
       </filter-mapping>
      
       <servlet>
       <servlet-name>Seam Resource Servlet</servlet-name>
       <servlet-class>
       org.jboss.seam.servlet.SeamResourceServlet
       </servlet-class>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>Seam Resource Servlet</servlet-name>
       <url-pattern>/seam/resource/*</url-pattern>
       </servlet-mapping>
      
       <!-- Faces Servlet -->
      
       <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>*.seam</url-pattern>
       </servlet-mapping>
      
       <!-- JSF parameters -->
      
       <context-param>
       <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
       <param-value>.jspx</param-value>
       </context-param>
       <context-param>
       <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
       <param-value>com.sun.facelets.FaceletViewHandler</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.DEVELOPMENT</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.LIBRARIES</param-name>
       <param-value>/WEB-INF/tags/mocia.taglib.xml</param-value>
       </context-param>
       <context-param>
       <param-name>
       org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL
       </param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
       <param-value>true</param-value>
      
       </context-param>
       <session-config>
       <session-timeout>10</session-timeout>
       </session-config>
       <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
      
      
      </web-app>
      


      Thanks in advance.