Unable to resolve ViewExpiredException through web.xml in JSF 2.2 - jsf-2.2

I am trying to resolve an apparently simple issue but so far no success.
I am developing a web application in JSF 2.2 with PrimeFaces 5.3 and tomcat 8 . I am trying to deal with ViewExpiredException, so that I can redirect the user to index or login page whenever session timeout occurs. I tried adding error-page tag in web.xml to catch the exception and redirect on login page, but no success.
I followed this link (along with several others) to seek guidance but as I mentioned earlier, it did not work for me.
Any help will be highly appreciated.
Below is my application's web.xml file:
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ricpacs</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{themeSwitcherView.selectedTheme}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<session-config>
<!-- Session idle timeout in min. -->
<session-timeout>1</session-timeout>
</session-config>
<error-page>
<exception-type>
javax.faces.application.ViewExpiredException
</exception-type>
<location>/index.jsp</location>
</error-page>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/x-font-ttf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>svg</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I have tried both values (Development and Production) for PROJECT_STAGE. But that did not help either.

Its always better to study books and detailed guides before implementing something new:-). After reading the PrimeFaces 5.3 user guide, I found out that in order to utilize built-in exceptionHandler feature of PrimeFaces, one must first configure it in faces config.xml file. The configuration is as given below:
<faces-config>
.
.
.
<application>
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
.
.
.
</faces-config>
After that, configure web.xml for ViewExpiredException as under:
<web-app>
.
.
.
<error-page>
<exception-type>
javax.faces.application.ViewExpiredException
</exception-type>
<location>/index.jsp</location> <!-- type whatever suits your environment and requirements -->
</error-page>
.
.
.
</web-app>
And thats it. Your ViewExpiredException will now be caught by built-in ExceptionHandler.

Try to use this for capture ViewExpiredException on ajax requests:
<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
You can add this code to footer section in your template, so you do not have to place it on every page.

Related

How to Change url localhost spring?

I´m using spring mvc, I have got a project (Apliconta2Web) and your url is //Apliconta2Web/, but if i copy this project and change your name by (Apliconta3WebPrimefaces) when i push button run as i want url //Apliconta3WebPrimefaces/ but always i have got //Apliconta2Web/.
I have changed servlet-name. and add server the name is Apliconta3WebPrimefaces(Apliconta2Web)
How i can change it? Very thank. sorry by my english. i´m learning.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>Aplicacion Web Apliconta3WebPrimefaces</display-name>
<servlet>
<servlet-name>apliconta3webPrimeFaces</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>apliconta3webPrimefaces</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

Issue with name appServlet-servlet.xml

Hi guys I'm working with Spring 3.2.3, hibernate 4.2.2 and org.springframework.security 3.0.5. Before I start working with security in spring, my context file was called servlet-context.xml and everything worked fine. Since I start using org.springframework.security 3.0.5 when I try to run my application I get the error:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/appServlet-servlet.xml]
My web.xml is:
<?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">
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Notice that I'm specifying my servlet-context.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
If I leave my web.xml just like this and copy/paste my servlet-context.xml content in a new file called appServlet-servlet.xml, everything works fine. This is confusing for me since I told web.xml that my context file name was servlet-context.xml. Am I forced to call my context file as appServlet-servlet.xml??. Of course, if I delete servlet-context.xml and leave appServlet-servlet.xml making the specficiation in web.xml, works fine.
I just wanna know if is obligatory to call my context file as appServlet-servlet.xml if I want to use spring security in my app.
This is not strange. Spring works this way. Since your DispatchServlet name is appServlet, Spring automatically tries to find the servlet context that has the same name, here "appServlet-servlet.xml".
Here is a page that may help : http://syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

This the file web.xml in WEB-INF
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>glpi.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
I think you are missing the context loader listener(to pick your spring context file(s)).
Add this to your web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
You could also check out the Initial web configuration section # http://static.springsource.org/spring/docs/2.0.x/reference/beans.html
You have both ContextLoaderServlet and DispatcherServlet set to load-on-startup = 1. That means either one of them could start first, and you need the ContextLoaderServlet to start first, since that's what creates the root WebApplicationContext that your error says is missing. So leave ContextLoaderServlet's load-on-startup at 1, and change the DispatcherServlet's to 2 or higher.
Actually, it's preferred to use ContextLoaderListener instead of the Servlet unless you're on a really old container where the Listener doesn't work properly.
Add following code in web.xml file, bcs it looks for contex to load so we have to declare it initially.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
I've recently stumbled upon the same issue, and I knew for sure it couldn't be caused by misconfiguration because I've copied the entire working Tomcat installation from another machine. Yet I kept getting the same exception:
java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered?
As I've eventually figured out, it was a wrong JVM version that broke the application: this one used Java 7, whereas the working instance (and the webapp) was on Java 8.
Hope it helps someone struggling with this counter-intuitive error message.

Undeployed application at context path

i'm facing an error while trying to run my application, here is the error:
OK - Undeployed application at context path /gest_project In-place
deployment at C:\Users......\target\gest_project Deployment is in
progress...
deploy?config=file%3A%2FC%3A%2FUsers%2Fnadya%2FAppData%2FLocal%2FTemp%2Fcontext1123098247565520222.xml&path=/gest_project
FAIL - Deployed application at context path /gest_project but context
failed to start The module has not been deployed. at
org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:187)
at
org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:167)
at
org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:123)
at
org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:208)
at
org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:154)
on tomcat log i have this:
GRAVE: Error listenerStart 11 sept. 2011 23:37:04
org.apache.catalina.core.StandardContext startInternal GRAVE:Error
Starting context [/ gest_project] following previous errors
here is my 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">
<!--Upload Filters-->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<!--End Upload Filters-->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Theme Aristo -->
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>start</param-value>
</context-param>
<!-- FIN -->
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/admin-direction.xhtml</welcome-file>
</welcome-file-list>
<!-- Add Support for Spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
<!-- JSF mapping -->
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
thanks a lot
(Not an answer)
Your errors are pretty generic and could be caused by lots of different problems in many other places apart from your web.xml. (The application-context, missing libraries, etc...)
You'll have to dig deeper (other files or look below in the same files) to find an error with more relevant information.
Try to find whether your application is up and running without any errors when you start the server. With that you eliminate any server configuration and dependency issues.
To do that:
1) Stop your tomcat server. Clean/Backup all log files.
2) If 'manager' app is not enabled, then try to enable it.
3) Start the tomcat server. Observe the start up logs for any errors.
4) If every thing is fine in the logs, then go to app manager 'http://localhost:8080/manager/'
to check whether your app is up and running (started) mode.
5) Now try to access the page or URL.
with this you could pin point the possible areas of error.
Problem could be also caused by lack of permissions. In my case I gave permissions (to everyone full access, because I'm not sure to who exactly give them) to folder containing Tomcat. This solved my problem.

"Unable to read TLD META-INF/jsf_core.tld from jsf-impl-2.0.jar" error when integrating JSF

We have a Struts+Spring+Hibernate Application and we are trying to integrate JSF. For that we have done some configuration in web.xml and struts-config.xml. I have added some
JAR files to WEB-INF/lib.
The jar files containing in my WEB-INF/lib are listed here:
antlr-2.7.6rc1.jar,asm.jar,asm-attrs.jar,bsh-2.0b2.jar,c3p0-0.9.1.2-jdk1.3.jar,cglib-2.1.3.jar,commons-beanutils-1.7.jar,commons-betwixt-0.8.jar,commons-cli-1.0.jar,commons-codec-1.3.jar,commons-collections-3.jar,commons-dbcp-1.2.1.jar,commons-digester-1.7.jar,commons-discovery-0.2.jar,commons-fileupload.jar,commons-httpclient-3.1.jar,commons-io-1.3.1.jar,commons-lang-2.3.jar,commons-logging-1.1.jar,commons-pool-1.2.jar,commons-validator.jar,connector-1_5.jar,dom4j-1.6.1.jar,ehcache-1.1.jar,el-api-6.0.20.jar,el-impl-2.2.0-SNAPSHOT.jar,hibernate-3.1.3.jar,jetty-util-6.0.0,.jar,servlet-api-2.3.jar,spring-2.5.6.jar,standard.jar,struts.jar,xercesImpl-2.6.2.jar,xmlParserAPIs-2.6.2.jar,xstream-1.3.1
The below jar file are the ones newly added for integrating JSF:
jsf-api-2.0.jar,jsf-impl-2.0.jar,myfaces-jsf-api-1.0.9.jar.jar.jar,struts-faces-1.3.10.jar
My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SSHIntgr</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/config/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>locale</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- struts-faces configuration start -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My struts-config.xml is
<struts-config>
<form-beans>
<form-bean name="usrForm" type="com.sshi.web.form.UsrForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" type="com.sshi.web.action.LoginAction"
name="usrForm" scope="request">
<forward name="allowUser" path="/pages/Welcome.jsp"/>
<forward name="denyUser" path="/index.jsp"/>
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.apache.struts.faces.
application.FacesRequestProcessor"/>
</controller>
<message-resources key="MessageResources" parameter="MessageResources" null="false" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/config/validator-rules.xml,/config/validation.xml" />
<set-property property="stopOnFirstError" value="true" />
</plug-in>
</struts-config>
I am using Spring source toll suite, Tomcat 5.5 and JDK 1.5.
My Tomcat 5.5\common\lib contains JAR files
commons-el.jar,jasper-compiler.jar,jasper-compiler-jdt.jar,jasper-runtime.jar,jsp-api.jar,naming-factory.jar,naming-factory-dbcp.jar,
naming-resources.jar,servlet-api.jar
My Server is starting properly but not able to load JSP page, I am getting the exception as
org.apache.jasper.JasperException: Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:/SSHIntgr/WEB-INF/lib/jsf-impl-2.0.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: com.sun.faces.taglib.jsf_core.CoreValidator
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:179)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
How can I solve this?
You're using tomcat 5.5 which is a Servlet 2.4 container, but JSF 2.0 requires Servlet 2.5 or newer.
So you have 2 options:
Upgrade your servletcontainer to a Servlet 2.5 comparible one (e.g. Tomcat 6.0).
Downgrade JSF to 1.2 which is compatible with Servlet 2.4.
Unrelated to the concrete problem: the file servlet-api-2.3.jar does not belong in WEB-INF/lib. Get rid of it. It's supposed to be already provided by the servletcontainer (in this case, the one in Tomcat's /lib). Keeping this file will only lead to missing class def or abstract method errors during runtime.

Resources