This content has been marked as final.
Show 1 reply
-
1. Re: Managed beans aren't constructed on JBoss 5.1.0 (works f
maxneves Sep 25, 2009 8:55 AM (in response to maxneves)Here's my web.xml used to deploy the application on Tomcat 6:
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" 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"> <display-name>abc</display-name> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <context-param> <param-name>facelets.REFRESH_PERIOD</param-name> <param-value>1</param-value> </context-param> <context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> <!-- Environment --> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</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>com.sun.faces.enableRestoreViewCompatibility</param-name> <param-value>true</param-value> </context-param> <!-- Rich Faces --> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>blueSky</param-value> </context-param> <!-- Defining and mapping the RichFaces/Ajax4JSF 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> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <!-- Authorization filter --> <filter> <filter-name>userSessionFilter</filter-name> <filter-class>com.abc.view.util.AuthorizationFilter</filter-class> </filter> <filter-mapping> <filter-name>userSessionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-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>*.jsf</url-pattern> </servlet-mapping> <session-config> <session-timeout>10</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/errorTimeOut.html</location> </error-page> <security-constraint> <display-name>Restrict XHTML files</display-name> <web-resource-collection> <web-resource-name>XHTML</web-resource-name> <url-pattern>*.xhtml</url-pattern> </web-resource-collection> <auth-constraint> <description>Grant access only for developers</description> <role-name>developer</role-name> </auth-constraint> </security-constraint> <security-role> <description>System developers</description> <role-name>developer</role-name> </security-role> </web-app>
We use the below web.xml to test on JBoss 5:<?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"> <display-name>abc</display-name> <!-- enabling JBossSerialization --> <context-param> <param-name>com.sun.faces.serializationProvider</param-name> <param-value>org.jboss.web.jsf.integration.serialization.JBossSerializationProvider</param-value> </context-param> <!-- startup messages --> <context-param> <param-name>com.sun.faces.displayConfiguration</param-name> <param-value>true</param-value> </context-param> <!-- JSF Config params --> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</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>facelets.REFRESH_PERIOD</param-name> <param-value>1</param-value> </context-param> <!-- tells to JSF to not render comments in jsf files --> <context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>com.sun.faces.enableRestoreViewCompatibility</param-name> <param-value>true</param-value> </context-param> <!-- Environment --> <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <!-- JSF-JBoss config --> <context-param> <param-name>com.sun.faces.numberOfViewsInSession</param-name> <param-value>15</param-value> </context-param> <context-param> <param-name>numberOfLogicalViews</param-name> <param-value>15</param-value> </context-param> <context-param> <param-name>com.sun.faces.verifyObjects</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.forceLoadConfiguration</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.disableVersionTracking</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.enableHtmlTagLibValidator</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.preferXHTML</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.compressViewState</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>com.sun.faces.responseBufferSize</param-name> <param-value>4096</param-value> </context-param> <context-param> <param-name>com.sun.faces.clientStateWriteBufferSize</param-name> <param-value>8192</param-value> </context-param> <context-param> <param-name>com.sun.faces.validateXml</param-name> <param-value>false</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_05. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.enableLazyBeanValidation</param-name> <param-value>true</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_05. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.enabledLoadBundle11Compatibility</param-name> <param-value>false</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_05. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.clientStateTimeout</param-name> <param-value>none</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_05. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.serializeServerState</param-name> <param-value>false</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_08. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.enableViewStateIdRendering</param-name> <param-value>true</param-value> </context-param> <context-param> <description>Added in Mojarra 1.2_08. See wiki.jboss.org/wiki/Wiki.jsp?page=UpgradeToMojarra1_2_08</description> <param-name>com.sun.faces.enableScriptsInAttributeValues</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name> <param-value>false</param-value> </context-param> <!-- RichFaces config --> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>blueSky</param-value> </context-param> <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> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <!-- Authorization filter --> <filter> <filter-name>userSessionFilter</filter-name> <filter-class>com.abc.view.util.AuthorizationFilter</filter-class> </filter> <filter-mapping> <filter-name>userSessionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Servelet config --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <session-config> <session-timeout>10</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/errorTimeOut.html</location> </error-page> <security-constraint> <display-name>Restrict XHTML files</display-name> <web-resource-collection> <web-resource-name>XHTML</web-resource-name> <url-pattern>*.xhtml</url-pattern> </web-resource-collection> <auth-constraint> <description>Grant access only for developers</description> <role-name>developer</role-name> </auth-constraint> </security-constraint> <security-role> <description>System developers</description> <role-name>developer</role-name> </security-role> </web-app>
The thing is: no matter what web.xml we use, we get the same problem on managed-beans: neither constructors nor methods flagged with @PostConstruct aren't called.
We realized this problem with JBoss exactly because whenever we fire a button or hyperlink (having an action=#{welcome.doSomething} ), 'doSomething()' manipulates objects that should be initilized on 'init()' and, since it isn't called, we got exceptions. After analizing the logs, we figured out this problem.
Let me give a concrete example
We have a managed-bean called 'Login' (the only one session-scoped) which isn't a subclasse of 'BaseBean':public class Login { private static final Logger log = Logger.getLogger(Login.class); private String loginUsername; private String loginUserpwd; private String errorMessage; public Login() { log.debug("Login constructor"); } @PostConstruct public void init() { log.debug("hello init"); // etc... } public String connectUser() { // some code // retrieve the sessionId, debug purposes //true = if the session does not exist, getSession create a new one HttpSession httpSession = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true); log.debug("sessionId = " + httpSession.getId()); // etc...
Well, we runned the application on JBoss, we got the following logs:13:46:34,088 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221053)] Started in 1m:38s:245ms 13:47:41,986 INFO [STDOUT] DEBUG 0 - com.abc.view.bean.Login.<init>(Login.java:29) - Login constructor 13:51:35,822 INFO [STDOUT] DEBUG233899 - com.abc.view.bean.Login.postIdenfication(Login.java:79) - sessionId = 548FD8FE3310C30DBB40554FBEB2AA45
Running on Tomcat yields:DEBUG 0 - com.abc.view.bean.Login.<init>(Login.java:29) - Login constructor DEBUG 0 - com.abc.view.bean.Login.init(Login.java:34) - hello init DEBUG 4110 - com.abc.view.bean.Login.postIdenfication(Login.java:79) - sessionId = 8ABF83F072786A607BD204E9B763971B
What I concluded so far
I said in the title that the managed beans weren't constructed when deploying on Jboss. It's wrong (thinking in terms of Java, it would be a very weird situation...).
However, the methods flagged with the annotation @PostConstruct aren't called. We don't have this problem with Tomcat.
I'm considering to use the "straighforward" workaround: call my @PostConstruct flagged methods in the constructor.
My reformulated question
Does anyone have any idea about what's going on with @PostConstruct and JBoss?
Thanks a lot
Max