Facing myFaces error when migrating from WAS8 to WAS9? - jsf-2.2

We are currently migrating our application from WAS8 to WAS9. We use JSF 2.2 and Primefaces 4.0. In WAS8 application works fine.But in WAS9 we are getting the following error:
Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException: /pages/xyz.xhtml - No saved view state could be found for the view identifier: /pages/xyz.xhtml
Our web.xml looks like following :
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</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.PARTIAL_STATE_SAVING</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.BUILD_BEFORE_RESTORE</param-name>
<param-value>true</param-value>
</context-param>
Tried changing STATE_SAVING_METHOD to client.But that is not working. Can anyone kindly help me in resolving this error. Thanks in advance.

I'd prefer to comment, but I do not have enough points.
It's hard to say what could be the causing this without more information.
Web.xml seems fine. Otherwise factors that can cause this error is session expiration or an problem with the cookies.
Another possibility is that javax.faces.ViewState may be corrupted?
My idea is that org_apache_myfaces_NUMBER_OF_VIEWS_IN_SESSION may need to be increased?
http://myfaces.apache.org/core20/myfaces-impl/webconfig.html#org_apache_myfaces_NUMBER_OF_VIEWS_IN_SESSION
But please read more about the viewexpiredexception below and I hope that may help you identity the problem.
javax.faces.application.ViewExpiredException: View could not be restored

Related

Servlet Web Application Context from filter

I try to get the spring web application context from a filter.
I was previously getting it through:
WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext())
It was ok, because I was getting what is called I think the ROOT web application context.
Now, I wanted to move all my spring definition like that in web.xml :
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext instead of default XmlWebApplicationContext. -->
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<!-- Custom web configuration annotated class. -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>foo.bar.WebConfiguration</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I removed the "old" definition from web.xml :
<!-- <context-param> -->
<!-- <param-name>contextConfigLocation</param-name> -->
<!-- <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> -->
<!-- </context-param> -->
<!-- <listener> -->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->
<!-- </listener> -->
Now, I have no more "ROOT" web application context, and the filter cannot get the another web application context.
I saw that there is another call :
WebApplicationContextUtils.getWebApplicationContext(sc, attrName)
it allows to specify as second argument the "attribute", it is in fact the web application context you want.By default, it is "org.springframework.web.context.WebApplicationContext.ROOT".
I think I have to call this method but I don't know what to put as second parameter.
PS : I also tried to use org.springframework.web.filter.DelegatingFilterProxy, but tomcat throwed the error that he dont find the classic (ROOT) web application context :
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
BUT THERE IS ANOTHER CONTEXT, it is just defined in another way. It is not possible I am the only one trying to get another context that the ROOT.
Thanks to have read so far.
I just read your answer, and yes I figured it out yesterday night ;-)
I added the ROOT context, defining it like that:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>foo.bar.WebConfiguration</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
And its working, the filter can acces to the service directly with Autowiring.
I still have the feeling that my architecture is dirty because the ROOT and "dispatcher" context are the same, I think it's not a good practice.
Maybe I'll try later to split the "WebConfiguration" in two.
Thank you anyway!

How to put two param-values in one context-param in Spring?

Problem: I have two contextConfigLocation parameters, one with #Configuration classes for spring-social-facebook and one with xml-file for app:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.communicator.core.social.facebook.config</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/root-context.xml</param-value>
</context-param>
Both of them use one param-name, and I don't know how to fix it.
You will be try this
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/root-context.xml,
com.communicator.core.social.facebook.config
</param-value>
</context-param>
You can use white space to separate each parameter within <param-value> like this.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/resources/spring/*.xml /WEB-INF/resources/module/*.xml /WEB-INF/resources/function/*.xml /WEB-INF/resources/bean/*.xml</param-value>
</context-param>
After test all answers, none works for me. I found the solution in this post JSF2 how to specify more than one custom element library in web.xml file
<param-value>com.communicator.core.social.facebook.config;/WEB-INF/root-context.xml</param-value>
Servlet spec says that you can have only one value for any context parameter. So, you are left with going with delimited list only.
<context-param>
<param-name>Hosts</param-name>
<param-value>ex1.com,ex2.com,.....</param-value>
</context-param>

JSF 2 h:messages appears on the end of the form

I have a screen which is implemented in JSF2 and I have validations on some of the fields, and when an error appears for a field that has no
<h:message for="fieldName" />
it always appear on the end of the screen with no style
I want to hide the messages summary even if I don't handle those validations
I guess they are just warnings that you see when your project stage is set to Development.
In web.xml file, change:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
to:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
and the messages disappear.
It is a feature of JSF 2 that shows you diagnostic messages when you are on Development stage. Actually you should changed that value in web.xml only when you want to put the project in production.

java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext

I am deploying Portlets on Liferay 5.2.3 on Tomcat 6. I get this error only for one of the portlet.
java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext
I did some research and found out that Spring was instantiating a portlet application context when it need a web one. But in my web.xml I am only defining contextLoaderListner
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
And to top it off, if a different *.jar file was being looked up by Spring, then why would my other portlets get deployed except one?
After couple of redeployments I get that to a fix. Can someone put some light on?
The root cause seems to be a static variable in the portal/application server "hanging onto" an instance of a class from the portlet. Two common culprits are log4j and java logging, both of which are commonly used by application containters.
See log4j and the thread context classloader and http://logback.qos.ch/manual/loggingSeparation.html for more discussion of loggers. The suggestion is to use SLF4J with logback OR to be sure to put log4j.jar in your WAR file so it is in the right classloader (although some containers will thwart this solution).
Also, some other class that is present in the container may be the cause. Logging is just a common problem.
Sounds like you are not defining the contextConfigLocation? in web.xml you should also have something like this in addition to the contextLoaderListener:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Where applicationContext.xml is a normal config file for a webapp.
You should also have this in your web.xml if using spring portlet MVC:
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
In your portlet.xml I guess you have something like this to specify your portlets:
<portlet>
<portlet-name>sample</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Sample Portlet</title>
</portlet-info>
</portlet>
If you haven't already, see the spring portlet mvc reference documentation
Hope it helps.

Multiple config files for Spring Security

I'm quite new to all things Spring, and right now I'm developing an application that uses Spring, Spring MVC and Spring Security.
My problem is that I'm using two dispatcher Servlets, one for /csm/*.html and another one for *.html and I'd like to have one Spring Security configuration file per servlet.
Is this possible at all?, if so, could you point me to an example?.
This answer relates to springframework 2.5.6, it might have changed in later versions.
use the pattern /WEB-INF/[servlet-name]-servlet.xml or specify it in the web.xml like this:
<servlet>
<servlet-name>handler</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<!-- override default name {servlet-name}-servlet.xml -->
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-myconfig.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
If you do not set the contextConfigLocation it defaults to handler-servlet.xml (at least in this example).
application wide stuff belongs into /WEB-INF/applicationContext.xml.
But you also can change the default and even add multiple files:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/spring-dao-hibernate.xml,
WEB-INF/spring-services.xml,
WEB-INF/spring-security.xml
</param-value>
</context-param>
you can find a more specific answer on the spring website, the documentation is quite good.

Resources