PrettyFaces redirect doesn't work - jsf

I'm trying to set view page for particular URL, but it doesn't work, here is a code:
pretty-config.xml:
<pretty-config>
<url-mapping id="loginPage">
<pattern value="/app"></pattern>
<view-id>/loginPage.xhtml</view-id>
</url-mapping>
</pretty-config>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
version="3.0">
<display-name>FiranyCRM</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>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
If I set url in browser like this: FiranyCRM/loginPage.xhtml then view will load, but when I change loginPage.xhtml into /app then it doesn't work and error appears on browser "Not found", console in eclipse doesn't say anything about it

Related

Glassfish5: JSF FacesServlet is not called

Glassfish5: JSF FacesServlet is not called.
example.ear
example_ejb.jar
example_web.war
META-INF/application.xml
META-INF/application.xml
<application 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/application_8.xsd"
version="8">
<module>
<ejb>example_ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>example_web.war</web-uri>
<context-root>example_web</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
example_web.war
WEB-INF/web.xml
home.xhtml
WEB-INF/web.xml
<web-app 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-app_4_0.xsd"
version="4.0">
<servlet>
<display-name>Faces Servlet</display-name>
<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>
Deployed example.ear to Glassfish5, successful.
But
http://localhost:8080/example_web/home.xhtml
HTTP Status 404 - Not Found
Set breakpoint in FacesServlet.java, the service() method is not called in debug mode.

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.

JSF not rendered through web.xml <welcome-file> only

Using JSF 2.2 with Tomcat 7.0, trying to run my project on the server using web.xml, but my JSF is never rendered. When running my index.xhtml file through run as on tomcat, the jsf is displayed without any problems at all. Here is my web.xhtml:
<?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"
version="3.0">
<display-name>ProcessOrderNewGreg</display-name>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
<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>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>
<welcome-file-list>
<welcome-file>ProcessOrderNewGreg/index.xhtml</welcome-file>
<welcome-file>ProcessOrderNewGreg/index.xhtml/index.jsf</welcome-file>
<welcome-file>ProcessOrderNewGreg/index.xhtml/index.htm</welcome-file>
<welcome-file>ProcessOrderNewGreg/index.xhtml/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My url when running index.xhtml through run as:
http://localhost:8080/ProcessOrderNewGreg/index.xhtml
By setting my web.xml file to this:
<?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"
version="3.0">
<display-name>ProcessOrderNewGreg</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I was able to render all of my JSF components.

JSF 2 Restful Paths for facelets

My JSF 2.0 basic (optional) web.xml structure is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app … version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app
So if I call /mypage.jsf I get mypage.xhtml and that's good but:
how can I have a behaviour like "/mypage" => mypage.xhtml (without *.jsf extension) ?
I'm sure I can do it, I saw that somewhere I don't remember.
What's the url pattern to associate an extension-less uri to jsf mapping?
Thank you

Remove faces servlet url pattern and page extension from url

i have a command link in my page which looks like:
<h:commandLink value="Add user" action="add?faces-redirect=true" />
and when i click it, it goes to url:
http://localhost:8080/myapp/faces/add.xhtml
but i want the url to be:
http://localhost:8080/myapp/add
how to do that ?
i am using spring 3, jsf 2
this 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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>myapp</display-name>
<!-- 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>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/users.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<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>*.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>
You can use PrettyFaces for it.

Resources