Why is my function not found? - jsf

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.

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.

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

Redirect from index.jsp welcome file to map.xhtml JSF page

I am try to make a my first jsf2 project run on jboss7.1
I want to redirect from the index.jsp to map.xhtml
that's what I try in my index.jsp and all of them didn't work please help
<%=response.sendRedirect("map.html") %>
<%=response.sendRedirect("/map.html") %>
<%=response.sendRedirect("map.xhtml") %>
<%=response.sendRedirect("/map.xhtml") %>
<%=response.sendRedirect("map.jsf") %>
<%=response.sendRedirect("/map.jsf") %>
and this is my faces-config.xml
<faces-config
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-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>myproject</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>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Don't do it the hard way.
Change
<url-pattern>*.jsf</url-pattern>
to
<url-pattern>*.xhtml</url-pattern>
and change
<welcome-file>index.jsp</welcome-file>
to
<welcome-file>map.xhtml</welcome-file>
This way map.xhtml becomes the welcome file and you can now stop fiddling with virtual URLs like .jsf and as a bonus, you can get rid of the legacy JSP file altogether.

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
...

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