Here how look my .jspx files:
<?xml version='1.0' encoding='utf-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML" doctype-system="http://www.w3.org/TR/html5"/>
<jsp:directive.page contentType="text/html;charset=utf-8"/>
<f:loadBundle basename="my.pack.resource" var="r"/>
<f:loadBundle basename="my.pack.error" var="e"/>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title> Some title </title>
<jsp:directive.include file="/temp/myLayout.jspf" />
</head>
<body>
<h:form>
<h:commandLink .........
</h:form>
</body>
</html>
</f:view>
</jsp:root>
In order to keep my view files clear and small
I would like to put all above and after body in
templates and include it in my .ispx files and pass title as parameter.
If anybody knows solution, please help.
EDIT
I have changed my view from .jspx to .xhtml, but my servlet filters now don't work.
Here my web.xml:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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"
version="2.5">
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml;*.jsf</param-value>
</context-param>
<filter>
<filter-name>loginFilter</filter-name>
<filter-class>my.pack.filterpack.LoginFilter</filter-class>
</filter>
<filter>
<filter-name>remebermefilter</filter-name>
<filter-class>my.pack.filterpack.RemeberMeFilter</filter-class>
</filter>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>my.pack.filterpack.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/view/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>remebermefilter</filter-name>
<url-pattern>/login/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
<dispatcher>FORWARD</dispatcher>
</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 mappings -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<error-page>
<error-code>500</error-code>
<location>/index.jsp</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/viewExp.jsp</location>
</error-page>
<listener>
<listener-class>my.pack.timer.MyJobManager</listener-class>
</listener>
</web-app>
This is one of the reasons why JSP(X) is abandoned, deprecated and succeeded by Facelets 4 years ago. JSP(X) doesn't offer easy templating capabilities in order to achieve this kind of requirements.
Just migrate to Facelets. Rename .jspx to .xhtml and replace <jsp:xxx> tags by <ui:xxx> tags. Your functional requirement is answered in 2nd example of How to include another XHTML in XHTML using JSF 2.0 Facelets?
Facelets is natively available in JSF 2.x. If you're still using JSF 1.x, then you can just install it separately as per its documentation.
Related
I am fairly new to Coding with Frameworks. I want to build a Website using JSF and found BootsFaces as a Framework. So I downloaded BootsFaces and followed https://www.bootsfaces.net/quick-start.jsf to get everything going. I added the .jar into the Java Build Path and started a Project like the quick-start. So far so good. Then I wanted to implement some more "advanced" stuff. So I tried to add https://showcase.bootsfaces.net/forms/buttonGroups.jsf just to test if everything works. It didn't, If I copy
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
My Site doesnt show anything when it loads.
Here is my index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:b="http://bootsfaces.net/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Basic Page</title>
</h:head>
<h:body>
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Mew</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>BootsFaces_USETHEME</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I use Glassfish as a Server if thats important.
Did I forget/not see something very basic? Or isn't BootsFaces even supposed to work like this?
I am using RichFaces and jsf 2.but when I moved to facelets some of
the rich component doesnt works for me. I am using
richfaces-api-3.3.4.Final.jar,
richfaces-impl-jsf2-3.3.4.Final.jar,
richfaces-ui-3.3.4.Final.jar.
tomcat version is 7.0.23
netbeans 7.3.1
I have configured the following details in web.xml
<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>
facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE
</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</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>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</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>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
<application>
<view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
</application>
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:form id="studentFormId" binding="#{StudentDetail.initForm}">
<rich:panel id="Student" >
<f:facet name="header">
<h:outputText value="Student DOB" />
<rich:calender/>
</f:facet>
</rich:panel>
</h:form>
</ui:composition>
</html>
When I deploy after clean and build it shows the following error.
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.
config.ConfigureListener java.lang.RuntimeException: com.sun.faces.config.ConfigurationException:
CONFIGURATION FAILED! Must have aConstructor that takes in a ComponentConfig
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:273)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Must have a Constructor that takes in a ComponentConfig at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:449) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
... 43 more
Caused by: javax.faces.view.facelets.FaceletException: Must have a Constructor that takes in a ComponentConfig
at com.sun.faces.facelets.tag.AbstractTagLibrary$UserComponentHandlerFactory.<init> (AbstractTagLibrary.java:330)
at com.sun.faces.facelets.tag.AbstractTagLibrary.addComponent(AbstractTagLibrary.java:558)
at com.sun.faces.facelets.tag.TagLibraryImpl.putComponent(TagLibraryImpl.java:114)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processComponent(FaceletTaglibConfigProcessor.java:588)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processTags (FaceletTaglibConfigProcessor.java:368)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processTagLibrary(FaceletTaglibConfigProcessor.java:321)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.process(FaceletTaglibConfigProcessor.java:270)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:437)
... 44 more
Caused by: java.lang.NoSuchMethodException:org.richfaces.taglib.AjaxValidatorHandler.<init> (javax.faces.view.facelets.ComponentConfig)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at com.sun.faces.facelets.tag.AbstractTagLibrary$UserComponentHandlerFactory.<init>(AbstractTagLibrary.java:328)
... 51 more
Can anybody find what mistake I have done here?
RichFaces 3.x and JSF 2 works fine. I'm using JSF 2.2 and RichFaces 3.3.4.Final.
You need to disable built-in JSF 2 facelets and add dependency on old jsf-facelets 1.1.15 (as per https://developer.jboss.org/wiki/RichFaces333andJSF20).
However, keep in mind that Mojarra has a bug when it looks for DISABLE_FACELET_JSF_VIEWHANDLER instead of javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER as per specification.
I made a new IceFace project and tried to run it on my local host, however I got the following error message:
Nov 4, 2013 11:41:10 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring file:/Users/Alex/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/TEST/WEB-INF/faces-config.xml for modifications
2013-11-04 23:41:10.563:INFO:oejs.AbstractConnector:Started SelectChannelConnector#0.0.0.0:8080
2013-11-04 23:41:11.623:WARN:oejh.HttpGenerator:Ignoring extra content <html>
<head>
</head>
<body>
</body>
</html>
Nov 4, 2013 11:41:11 PM org.icefaces.impl.application.ExtendedExceptionHandler handle
WARNING: queued exception
java.lang.NullPointerException
at org.icepush.util.ExtensionRegistry.getBestExtension(ExtensionRegistry.java:69)
at org.icefaces.impl.push.servlet.ICEpushResourceHandler$ICEpushResourceHandlerImpl.beforePhase(ICEpushResourceHandler.java:171)
at org.icefaces.impl.push.servlet.ICEpushResourceHandler.beforePhase(ICEpushResourceHandler.java:111)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool
and here is my web.xml
<?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>TEST</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.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>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/icefaces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>org.icefaces.coalesceResources</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.icefaces.strictSessionTimeout</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.icefaces.ace.gmapKey</param-name>
<param-value>AIzaSyAATyWVqT2qNusNGmcVTyQ0QmymkpU-B5o</param-value>
</context-param>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
</web-app>
The two files I have under my WebContext is index.jsp which redirects to index.jsf and the other file is index.xhtml which contains the following :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
>
<h:head>
<title>ICEfaces 3</title>
</h:head>
<h:body>
<h:form id="iceForm">
<ace:panel header="Welcome to ICEfaces">
<h:panelGrid columns="1">
<ace:linkButton id="linkButton1" value="ICEfaces Overview" href="http://wiki.icesoft.org/display/ICE/ICEfaces+Overview"></ace:linkButton>
<ace:linkButton id="linkButton2" value="General Documentation" href="http://wiki.icesoft.org/display/ICE/ICEfaces+Documentation"></ace:linkButton>
<ace:linkButton id="linkButton4" value="Tutorials" href="http://www.icesoft.org/community/tutorials-samples.jsf"></ace:linkButton>
<ace:linkButton id="linkButton5" value="ACE components" href="http://wiki.icesoft.org/display/ICE/ACE+Components"></ace:linkButton>
</h:panelGrid>
</ace:panel>
</h:form>
</h:body>
</html>
i have tried switching the the welcome-file-list to
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file> <!--switched extension from html to xhtml -->
<welcome-file-list>
with this change my localhost will not crash, however I get a blank page (none of my JSF element shows up) I'm having a feeling it is because none of my JSf tags are getting parsed, however i don't really know where the problem is, can anyone please help me?
other information:
Im using Eclipse Java EE IDE for Web Developers
ICEFACES 3.3.0
Tomcat 3.0
Thanks.
update:
Changed my web.xml welcome-file-list to
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
and changed my servlet-mapping to
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
There is no crash now, but my JSF elements does not show up, i only get a blank page.
UPDATES:
Web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
I have tried .jsf and .xhtml inside the url-pattern tag both no luck
index.jsp
<html>
<head>
</head>
<body>
<%
//response.sendRedirect("./index.jsf");
%>
<jsp:forward page="main.jsf"/>
</body>
</html>
after Getting my page to load up, it becomes blank, so i right click on my page and view source, and this is what i found...
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
>
<h:head>
<title>ICEfaces 3</title>
</h:head>
<h:body>
<h:form id="iceForm">
<ace:panel header="Welcome to ICEfaces">
<h:panelGrid columns="1">
<ace:linkButton id="linkButton1" value="ICEfaces Overview" href="http://wiki.icesoft.org/display/ICE/ICEfaces+Overview"></ace:linkButton>
<ace:linkButton id="linkButton2" value="General Documentation" href="http://wiki.icesoft.org/display/ICE/ICEfaces+Documentation"></ace:linkButton>
<ace:linkButton id="linkButton4" value="Tutorials" href="http://www.icesoft.org/community/tutorials-samples.jsf"></ace:linkButton>
<ace:linkButton id="linkButton5" value="ACE components" href="http://wiki.icesoft.org/display/ICE/ACE+Components"></ace:linkButton>
</h:panelGrid>
</ace:panel>
</h:form>
</h:body>
</html>
Any ideas why this is happening?
I need some help in using a OmniFaces Feature.
I am trying to use the FacesExceptionFilter to redirect the user to an error page when an exception is encountered.
I have the following web.xml config
<?xml version="1.0" encoding="UTF-8"?>
<display-name>xxxxx</display-name>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>pages/secured/main.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-application-context.xml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>mytheme</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.SEPARATOR_CHAR</param-name>
<param-value>_</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.bdo.corpsoa.utilities.security.listeners.impl.CorpSoaSessionListener</listener-class>
</listener>
<filter>
<filter-name>facesExceptionFilter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>facesExceptionFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATH</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
<param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
</context-param>
<!-- <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> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher>
</filter-mapping> -->
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/pages/errors/viewExpired.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/WEB-INF/pages/errors/unHandled.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>
However when an exception happens the user is just redirected to the default 500 error page.
The redirection will only work if I move error pages out of the WEB-INF folder
/WEB-INF/pages/errors/pageNotFound.xhtml --> /pages/errors/pageNotFound.xhtml
But this would mean that the error page can now be accessed directly. But in the Omnifaces showcase this should be possible. I don't know what I am missing please help...
Here is the web.xml of the Omnifaces showcase that shows that error pages in the WEB-INF is possible.
<?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"
metadata-complete="false"
<display-name>OmniFaces Showcase</display-name>
<!-- Standard JSF settings. -->
<context-param>
<param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
<param-value>65535</param-value> <!-- 64KB. -->
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value> <!-- Should be -1 for production. -->
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/showcase.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Mojarra/RI specific settings. -->
<context-param>
<param-name>com.sun.faces.defaultResourceMaxAge</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks. -->
</context-param>
<!-- MyFaces specific settings. -->
<context-param>
<param-name>org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks. -->
</context-param>
<context-param>
<!--
MyFaces and Mojarra don't agree on the default setting for actually serializing state
in the session as opposed to just storing a reference. Mojarra's default is false, but
can be switched to true. MyFaces' default is true, and can be switched to false, which
we thus do below. See http://arjan-tijms.omnifaces.org/p/jsf-22.html#1127
-->
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<!-- OmniFaces specific settings. -->
<context-param>
<param-name>org.omnifaces.CACHE_SETTING_SESSION_MAX_CAPACITY</param-name>
<param-value>6</param-value>
</context-param>
<context-param>
<!--
All files in the 3 paths defined below will be scanned and made available
as extensionless JSF views. Since no explicit extension is given for scanning,
these paths should contain ONLY JSF (Facelets) files.
-->
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/showcase,/etc,/demo</param-value>
</context-param>
<context-param>
<!--
Redirects the faces views scanned /showcase/[PAGE].xhtml to /[PAGE].
A 404 would normally be preferred (and this is thus the default), but the showcase app
already has published /showcase/[PAGE].xhtml
-->
<param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
<param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
</context-param>
<!-- Servlets and filters. -->
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>facesExceptionFilter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>facesExceptionFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>gzipResponseFilter</filter-name>
<filter-class>org.omnifaces.filter.GzipResponseFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>gzipResponseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- Welcome files, error pages and mime types. -->
<session-config>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<welcome-file-list>
<!--
Note that an extension is used here, since the index file resides within the
root which has not been configured for FacesViews scanning.
-->
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/errorpages/expired.xhtml</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/WEB-INF/errorpages/database.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/WEB-INF/errorpages/bug.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/errorpages/500.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/errorpages/404.xhtml</location>
</error-page>
<mime-mapping>
<!--
Silence WebLogic's annoying "JSF1091: No mime type could be found for file" warning.
-->
<extension>xhtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
Summary
Redirect to error pages work if outside the WEB-INF.
Showcase shows that it should be possible.
I need help....
Thank you for your time
EDIT
It seems that "Redirect to error pages work if outside the WEB-INF." is not always true.
This error page will be displayed if outside of WEB-INF
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>#{"XXXXXXXX"}</h1>
</h:body>
</html>
This error page will not be displayed even if outside of WEB-INF. This Will result in the default 404 Page
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>ZZZZZZZZZ</h1>
</h:body>
</html>
It seems that the FacesExceptionFilter is actually working if I place an EL expression or jsf component on the jsf page.
For some reason this error page will not work and will produce The default 404 page.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>ZZZZZZZZZ</h1>
</h:body>
</html>
However this error page will work.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>#{"XXXXXXXX"}</h1>
</h:body>
</html>
I am using Primefaces 2.0.1 but the FileUpload component is not working properly. It uses JQuery uploadify behind the scenes. This 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">
<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>
<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>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
This is my index.xhtml :-
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:commandButton actionListener="#{NewJSFManagedBean.add}" value="add"/>
<p:fileUpload auto="false" widgetVar="fileUpl" fileUploadListener="#{NewJSFManagedBean.saveFile}"/>
</h:form>
</h:body>
</html>
I have following libraries in my classpath :-
primefaces 2.0.1
commons-beanutils
commons-beanutils-bean-collection
commons-digestor
commons-fileUpload
commons-io
commons-logging
jhighlight
The file gets correctly uploaded in /tmp but in browser it always says HTTP error. Please help me. It used to work till yesterday. But today i did a fresh installation of Glassfish and it has stopped working.
A filter needs to be added to web.xml. So, add these lines to web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
To be able to use the Primefaces fileUpload component, a few Apache Commons dependencies also need to be added:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
I have had some troubles with this component also. I seem to remember that by adding an id to the fileUpload component and/or the form, things started working for me. Worth a try.
i think you are missing enctype="multipart/form-data" in your h:form tag.
I had the same problem. And note that by deleting the cookies from my browser-firefox-and going to upload my application and it worked.
I'm using PRIMEFACES 2.2.1 and the problem is still there: HTTP error when Chrome or Firefox is used; all fine with IE. In my case, this apparently happens due to a reverse proxy shielding the actual server running the application. If the application is used through a direct URL reference (http://server:port/some path), it works fine; if the reverse proxy URL is used, the requests fail. I don't know why this fails in FF and GC and doesn't do so in IE.