facescontext null in jsf mojarra-2.0, jboss 6.0 and jboss 6.1
burgosjc Oct 8, 2011 7:31 AMHello everyone
happens that by invoking the method FacesContext.getCurrentInstance() returns null
alguna idea
I'm using
Jboss 6.1.0
JSF 2
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <filter> <filter-name>Pretty Filter</filter-name> <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class> </filter> <filter-mapping> <filter-name>Pretty Filter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping> <servlet> <servlet-name>jcaptcha</servlet-name> <servlet-class>com.selsa.arqos.ad.sso.presentacion.servlet.ImageCaptchaServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jcaptcha</servlet-name> <url-pattern>/jcaptcha.jpg</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> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>welcomeICEfaces.jsf</welcome-file> </welcome-file-list> <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/pages/public/viewExpired.xhtml</location> </error-page> </web-app>
faces-config
<faces-config version="2.0" 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_2_0.xsd"> <application> <message-bundle>com.selsa.arqos.gr.propiedades.resources.messagesValidation</message-bundle> <locale-config /> <resource-bundle> <base-name>com.selsa.arqos.gr.propiedades.resources.messages</base-name> <var>message</var> </resource-bundle> <resource-bundle> <base-name>com.selsa.arqos.gr.propiedades.resources.sso.messages</base-name> <var>message</var> </resource-bundle> </application> </faces-config>
Working to my problem I found the following:
The managed bean the'm extending a class which implements the methods for handling messages, if I move to managed bean these methods work
@ManagedBean(name="pruebaBean") @RequestScoped class PruebaBean extends AbstractMessage{ @PostConstruct protected void postConstruct(){ addInfo("Hola mundo); } }
public class AbstractMessage { protected FacesContext getCurrentContext() { return FacesContext.getCurrentInstance(); } public void addInfo(String msg) { addMessage(msg, FacesMessage.SEVERITY_INFO); } private void addMessage(String msg, Severity severity) { FacesMessage message = new FacesMessage(msg); message.setSeverity(severity); FacesContext ctx = getCurrentContext(); ctx.addMessage(null, message); } }
will be a bug or am I doing something wrong