PrettyFaces: poor performance on every request - jsf

registering for new users in the pretty forum (https://www.ocpsoft.org/support/forum/prettyfaces-users/) currently does not seem to work, so i ask here for help:
we started to include latest prettyfaces 3.4.2 in our jsf 2.2 project and recognized a pretty poor performance on every POST and GET request.
we removed all our custom filters and servlet-listener so that nothing special remains in the config files, but prettyfaces stays unusable, although the rewrite-engine seems to work in general:
http://localhost:8080/vision9/member/576
after removing the pretty dependencies, everything goes back to "normal" state...
does anybody have a hint for this problem?
Update:
Performance is only fine when project-stage is Production. Setting following context-params as taken from
https://www.ocpsoft.org/support/topic/huge-performance-drop-even-with-empty-config/
did not solve the performance issue:
<context-param>
<param-name>org.ocpsoft.rewrite.config.CONFIG_RELOADING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.ocpsoft.rewrite.annotation.BASE_PACKAGES</param-name>
<param-value>none</param-value>
</context-param>
here are our configuration files:
console-info during server-startup:
INFORMATION: RewriteFilter starting up...
Rewrite 3.4.2.Final initialized.
RewritePhaseListener starting up.
pom.xml:
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.6.8</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>3.4.2.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>3.4.2.Final</version>
</dependency>
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>vision9</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>/javax.faces.resource/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<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.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>
pretty-config.xml:
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="members">
<pattern value="/member/#{memberId}" />
<view-id value="/member.xhtml" />
</url-mapping>
</pretty-config>
faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<locale-config>
<default-locale>de</default-locale>
</locale-config>
<resource-bundle>
<base-name>messages</base-name>
<var>msg</var>
</resource-bundle>
<resource-handler>org.omnifaces.resourcehandler.UnmappedResourceHandler</resource-handler>
</application>

Related

calling Faces Servlet root URL throws Nullpointer

My web project's .war file has the context root myapp/something and it is defined in the application.xml of the EAR file.
In this project I have some Servlets that work fine with this. But now I added a Server Faces Servlet to the web.xml with the pattern /Monitoring/mySite.
The problem now is that if I call the URL http://somehost/myapp/something/Monitoring/mySite I end up in a NullPointer loop because there is no view available (known Websphere issue, fix for that here).
I thought by setting web/page.xhtml as the welcome-file in the web.xml this should be fixed, but it only applies to the context-root of the application, namely /myapp/something.
So what works is if I make the following calls:
http://somehost/myapp/something/Monitoring/mySite/web/page.xhtml
http://somehost/myapp/something
TL;DR
But I would like to see the page.xhtml when I call http://somehost/myapp/something/Monitoring/mySite.
How can I accomplish this?
/TL;DR
The following is the web.xml of the project:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="myProject" 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>This is mySite</display-name>
<!-- Change to "Production" when you are ready to deploy -->
<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>client</param-value>
</context-param>
<servlet>
<description></description>
<display-name>Monitoring</display-name>
<servlet-name>Monitoring</servlet-name>
<servlet-class>some.path.to.Monitoring</servlet-class>
</servlet>
<servlet>
<description></description>
<display-name>MonitoringExtended</display-name>
<servlet-name>MonitoringExtended</servlet-name>
<servlet-class>some.path.to.MonitoringExtended</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>FacesServlet</display-name>
<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>Monitoring</servlet-name>
<url-pattern>/Monitoring</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MonitoringExtended</servlet-name>
<url-pattern>/Monitoring/extended</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/Monitoring/mysite/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>web/page.xhtml</welcome-file>
<welcome-file>faces/web/page.xhtml</welcome-file>
</welcome-file-list>
Here the part of my application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application 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/application_5.xsd" version="5">
<display-name>myApplication</display-name>
<module>
<ejb>myApplication.jar</ejb>
</module>
<module>
<web>
<web-uri>myProject.war</web-uri>
<context-root>myapp/something</context-root>
</web>
</module>
</application>
Here the ibm-web-ext.xml (legacy, didn't touch it):
<?xml version="1.0" encoding="UTF-8"?>
<webappext:WebAppExtension xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:webappext="webappext.xmi"
xmi:id="WebAppExtension_1229358884593" reloadInterval="3"
reloadingEnabled="true" additionalClassPath="" fileServingEnabled="true"
directoryBrowsingEnabled="false" serveServletsByClassnameEnabled="true">
<webApp href="WEB-INF/web.xml#WebApp_ID" />
</webappext:WebAppExtension>
And finally the ibm-web-bnd.xml(also legacy, didn't touch it):
<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_123456789" virtualHostName="default_host">
<webapp href="WEB-INF/web.xml#WebApp_ID"/>
</webappbnd:WebAppBinding>
I solved this with a workaround.
What I did is a URL pattern to my page.xhtml, but renamed so it would fit my needs, like this:
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/Monitoring/mySite.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
With this I need a new folder Monitoring in my WebContent folder (for other project I guess it's the webapp folder). There I would place my mySite.xhtml.
Now I can call http://somehost/myapp/something/Monitoring/mySite.xhtml.
Not quite the solution I hoped for (I would like to eliminate the .xhtml), but it works.
And with this I also don't run into the Nullpointer loop bug, because there is no URL pattern that would create it.

How to use the Push of Primefaces 5 with GlassFish 4.0?

I create an example on eclipse to use push of primefaces 5 with glassfish 4.0. I copy code of primefaces's push (http://www.primefaces.org/showcase/push/chat.xhtml). I configuration in pom.xml like bellow:
pom.xml
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>webapp</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- Faces Implementation -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Faces Library -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Primefaces Version 5 -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<!-- Atmosphere -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<!-- File Upload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
<!-- JSP Library -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- JSTL Library -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
and for web.xml:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<!-- Following param only needed for MyFaces (TomEE, etc) -->
<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>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
After I finish all code like primefaces's push and deploy directly from eclipse to glassfish 4 and have error like bellow:
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Lorg/primefaces/push/EventBus;.
Please help me to find out the issue and deploy successful.
I'm a newbie in PFP/Atmosphere but for me it seems like the atmosphere API is missing. And since I've struggled a lot on making Primefaces 5.1 Push to work on Glassfish 4 I would like to share my setup with the community :)
<?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>MyProject</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
<!-- **************** FACES CONFIGURATION ******************** -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- **************** Primefaces PUSH (Athmosphere based) ******************** -->
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<!-- **************** Primefaces FILE UPLOAD ******************** -->
<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>
<!-- ********* PARTIAL SUBMIT <ENABLED> ********* -->
<context-param>
<param-name>primefaces.SUBMIT</param-name>
<param-value>partial</param-value>
</context-param>
<!-- ********* CLIENT_SIDE_VALIDATION <ENABLED> ********* -->
<context-param>
<param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
<param-value>true</param-value>
</context-param>
<!-- ********* FACELETS_SKIP_COMMENTS <ENABLED> ********* -->
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
</web-app>
My library setup is as follows: WEB-INF/lib/
-primefaces-5.1.jar
-vaadin-slf4j-jdk14-1.6.1.jar
-atmosphere-runtime-2.2.4.vaadin5.jar
-slf4j-api-1.7.10.jar
-commons-fileupload-1.3.1.jar
Note: I'm using Luna Service Release 1a (4.4.1) and I've found out that when I change my setup I have to remove my App from the Server, reboot the server, redeploy and Project->clean in order to make it work.
Hope this post can help.

Why is my function not found?

Here is my code
<html (...) xmlns:of="http://omnifaces.org/functions">
...
<c:set var="formattedDate"
value="#{of:formatDate(now, 'dd/MM/yyyy')}" />
When I run it, I get this error:
value="#{of:formatDate(now, 'dd/MM/yyyy')}" Function 'of:formatDate' not found
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
Here is my pom.xml
...
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.7</version>
</dependency>
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>JSFPlayground</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.xhtml</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>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
Possibly the Omnifaces lib has not been added to the classpath.
mvn clean install should do the trick.

JSF Mapping with Maven - starting using maven

hope you had a great day
For a few days I am trying to learn using Maven - cause I have heard that its good practice to create my projects with it.
And so what I did. Maven is quite difficult for my present abilities. Now I am trying to create JSF page and 've got problem with mapping. Maven has created a simple web.xml for me, its almost empty (it has just tag and its closed too). I have added JSF depenedency and made simple a.xhtml page with one button and text field. If I run it, it works fine. But If I enter some changes in web.xml - I would add mapping for *.jsf *.faces *.xhtml etc. it wont work anymore. I am sick about it, have no idea how to fix it.
Here is my present code:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maciej</groupId>
<artifactId>Mejwn</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Mejwn Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>Mejwn</finalName>
</build>
</project>
web.xml:
<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">
<welcome-file-list>
<welcome-file>a.xhtml</welcome-file>
</welcome-file-list>
<display-name>Archetype Created Web Application</display-name>
<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>
<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>
My project structure:
http://imagizer.imageshack.us/v2/800x600q90/13/qr18.jpg
(I cant add images, too low reputation for now:P)
Hope you can help me!
Thanks! ;)
Wow, I have fixed it. The problem was in pom.xml, I had to add those dependencies:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>
And all mappings and rendering JSF components(which hasnt been working as well) are fine now
Thanks and have a good day

JSF Map showed URL from localhost/testproject/testfolder/all/profile.xhtml to localhost/testproject/profile.xhtml

How can i map the URL localhost/testproject/testfolder/all/profile.xhtml to localhost/testproject/profile.xhtml? I dont want to display the whole structure of the folders behind. I it with URL-Pattern but that doesnt work. Can anyone give me a hint, how this could work in JSF 2.2?
<?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"
xmlns:web="http://java.sun.xom/xml/ns/javaee/web-app_3_0.xsd"
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">
<description>Testprojekt</description>
<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>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>faces/users/welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
you can use a Filter (URL Rewriting) to do it for you.
there are a lot of URL Rewrite Libraries online or you implement your own Filter
some thing like
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filerChain) throws IOException, ServletException {
HttpServletRequest httrequest = (HttpServletRequest) request;
String url = httrequest.getRequestURI().trim();
HttpSession session = httrequest.getSession(true);
//be aware of infinite loops. in case your url is only profile.xhtml and the redirect contains this file too, so i added the pattern faces before it
if (url.contains("faces/profile.xhtml")) { // this what pub User see in the url
StringBuilder forward = new StringBuilder();
forward.append("/testfolder/all/profile.xhtml?");
forward.append(httrequest.getQueryString());
request.getRequestDispatcher(forward.toString()).forward(request, response);
}
if(!response.isCommitted()){
try{
filerChain.doFilter(request, response);
}catch(Exception ex){
...
}
}
You need URL rewriting, I'm using prettyfaces as my URL Rewriting Library.
You can have even friendly URLs
prettyfaces
You just need to add it to your pom.xml
<!-- for JSF 2.x -->
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.8.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>2.0.8.Final</version>
</dependency>
Then create pretty-config.xml inside your /WEB-INF/ Folder
in your case, here's an example file of pretty-config.xml
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="profile">
<pattern value="/profile" />
<view-id value="/testfolder/all/profile.xhtml" />
</url-mapping>
</pretty-config>

Resources