JSF 2.0 FileNotFoundException - jsf

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

Related

JSF Primefaces navigation rules

I copied someone elses JSF project since I could not get the IntelliJ maven archetypes to download. Anyways that projects was functioning but did not contain a faces-config so I added it manually into the project folder:
+
+-WebContent
+--WEB-INF
+---faces-config.xml
+---web.xml
The faces config looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<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_0.xsd"
version="2.0">
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{loginBean.performLogin}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/home.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
That is the 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>Primefaces-Dashboard-Sample</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>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
And this is the button within the form:
<p:commandButton id="loginButton" action="#{loginBean.performLogin}"
value="send" ajax="true" style="float: right;">
</p:commandButton>
However I get the weird behavior that the page is not redirect rather the form content gets replaced by the content of home.xhtml. Using the standard commandButton however everything works as expected.
Is there any way to get this to work with primefaces?

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 sample project managed beans error, unable to print managed beans message to html

I started to implement a very basic JSF application but i am unable to print the JSF Managed Beans message to html..
Here is my code :
HelloWorld.java :
package com.project.managedbeans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
#ManagedBean(name="helloWorld", eager=true)
#RequestScoped
public class HelloWorld {
private String message;
public HelloWorld(){
System.out.println("Hello World Managed Bean is created");
}
public String getMessage(){
return "Hello World ! ";
}
public void setMessage(String message){
this.message = message;
}
index.html :
<!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">
<body>
#{helloWorld.message}
</body>
</html>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
and 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>jsfSampleProject</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>*.jsf</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>
</web-app>
and when i run the application on apache server, the page i see under
localhost:8080/jsfSampleProject/ is :
#{helloWorld.message}
I have JSF 2.1 Mojorra under Libraries tab. What do you think the problem is ?
Thanks.
The problem is that welcome file list accepts file names that are physically present in your web app, and that is index.xhtml. Note that none of your welcome files match that condition.
Next, your file is not handled by the FacesServlet. That is, requested URL does not correspond to the servlet URL mapping in your web.xml. Note that your mapping *.jsf doesn't match your requested files as well.
All in all, the following excerpt from web.xml will solve your problem:
<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>
Of course, you'll need the file index.xhtml at the root of your web application.

Nothing works When i add JSF related tags in web.xml

When i add JSF related tags to web.xml nothing is working and it gives an error. If I remove XML tags in web.xml then all .jsp and servlets are working fine. I also added jsf-api.jar,jsf-impl.jar,jstl.jar and standard.jar to lib folder of my project still it is not working so i added these jar files to lib folder in tomcat too but still it is not working.
Error1 with index.xhtml to url:
XML Parsing Error: no element found
Location: http://www.touchegolfmart.com/index.xhtml
Line Number 1, Column 1:
Erro2 with out index.xhtml to url
File not found
Firefox can't find the file at http://www.touchegolfmart.com/.
my web.xml file is
<?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">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Context path in server.xml in conf folder of tomcat is:
<Host name="touchegolfmart.com" appBase="/home/rathan">
<Alias>www.touchegolfmart.com</Alias>
<Context path="" reloadable="true" docBase="public_html" debug="1"/>
<!-- <Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>-->
</Host>
Folder structure is:
index.jsp
WEB-INF/classes
WEB-INF/lib
WEB-INF/faces-config.xml
WEB-INF/web.xml
WEB-lib/lib/jsf-api.jar,jsf-impl.jar,jstl.jar,standard.jar.
META-INF/context.xml
I quickly put some example.
Created T folder in webapp folder.
Created file hello.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
<h3>JSF 2.0 Hello World Example</h3>
<h:form>
<h:commandButton value="Click" action="welcome"></h:commandButton>
</h:form>
</h:body>
</html>
Created file welcome.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body bgcolor="white">
<h2>JSF 2.0 Hello World Example</h2>
</h:body>
</html>
After this created folder WEB-INF in T folder and created 2 files:
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>JSFHelloWorld</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/hello.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>
<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>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_0.xsd"
version="2.0">
</faces-config>
also in T/WEB-INF folder created folder lib, which has jsf-api-2.1.12.jar, jsf-impl-2.1.12.jar, jstl-1.2.jar files.
This works, but I don't used any POJO.
Instead of placing the files in the appBase folder manually, place a .war file and extract it through jar command then restarting the tomcat made my application work.

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