Glassfish5: JSF FacesServlet is not called - jsf

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.

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.

PrettyFaces redirect doesn't work

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

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 2.0 FileNotFoundException

getting the below exception when accessing http://localhost:8081/ReportGeneratorJSF/
com.sun.faces.context.FacesFileNotFoundException: /login.xhtml Not Found in ExternalContext as a Resource
I am using JSF 2.0
i have created a login.xhtml inside WEB-INF folder which is using templates of header.xhtml and footer.xhtml using basictemplate.xhtml
// login.xhtml
<ui:composition template="/WEB-INF/template/basictemplate.xhtml">
...
textboxs and submit button
...
</ui:composition>
// 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>ReportGeneratorJSF</display-name>
<welcome-file-list>
<welcome-file>faces/login.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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Can you please provide solution for it.
You have a problem in your files, you need to place them like this :
WEB-INF
- faces-config.xml
- web.xml
login.xhtml
header.xhtml
footer.xhtml
...

Not Found in ExternalContext as a Resource whilst running .xhtml in JSF

I created a dynamic web project in Eclipse and added the JSF jars manually to the lib (instead using maven). I provided faces servlet configuration in web.xml.
I am trying to see the hello.xhtml output of the file placed webinf folder. But it is throwing:
/hello.xhtml Not Found in ExternalContext as a Resource.
My directory structure is as,
LibraryPro
Java resoures
Webcontent
WEB-INF
lib
application.xml
hello.xhtml
the URL I am using is,
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_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">
<display-name>JavaServerFaces</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>hello.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>
</web-app>

Resources