Facelets parsing problem using JBoss v4.2.1 - java

I have a some.xhtml file with jsf libs in it. In <h:body> tag I am trying to display 2 words:
For the first one I use plain text: Hello
For the second one I use: <h:outputText value=" there"/>
I expect to see "Hello there", but only Hello is printed on the page. So I assume that the facelet is not parsed somehow in JBoss 4.2.1. It worked Apache 7. How can I fix it. May be something must be added to the web.xml or faces-config.xml files?
Thanks in advance
P.S. I open the page like this: http://localhost:8080/ProjectName/faces/some.xhtml
some.xhtml
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Title that rocks</title>
</h:head>
<h:body>
Hello
<h:outputText value=" there" />
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
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_2_5.xsd">
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</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_1_2.xsd"
version="1.2">
</faces-config>

JBoss 4.2 ships with a bundled JSF 1.2 implementation which will by default always get precedence over any JSF implementation which you include in your WAR. JSF 1.2 does by default not recognize Facelets as view technology, nor does it support any JSF 2.0 specific tags like <h:body>.
To tell JBoss that your WAR already bundles a JSF implementation, so that JBoss won't use its bundled JSF 1.2 for your webapp, you need to add the following context parameter to your web.xml:
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>

Open the page with .jsf suffix or /faces/
Which ever you defined in web.xml

Related

Getting 404 Status when trying to request JSF page

I have difficulties in running my eclipse jsf test project. I am using eclipse kepler, apache tomcat 7.0 and JSF 2.1.9.
Whenever I try to request my helloWorld.xhtml (url /localhost/helloWorldJSF/helloWorld.xhtml), it brings me to the 404 status saying that the requested resource is not available but I do not understand why.
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>HelloJSF</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>*.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>
</web-app>
And my helloWorldJSF.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.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>Hello JSF</title>
</h:head>
<h:body>
<h:form id="helloForm">
<h:outputText value="Hello JSF"></h:outputText>
</h:form>
</h:body>
What am I doing wrong? I have set the according libraries in the settings (JSF 2.1.9). The faces-config.xml also refers to version 2.1.
Thanks in advance!
I solved the problem by removing the server and adding a new server configuration.

JSF 1.2 + JBoss 5 not rendering jsf tags.

I'm trying to convert a .net app to JSF 1.2 to sit on our legacy JBoss server and I can't get the jsf tags to render. In my browser i see exactly what i see in eclipse.
Any suggestions are appreciated.
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"
version="2.5">
<display-name>WebDataViewer</display-name>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/tlds/formatter-taglib.xml</param-value>
</context-param>
<!-- JSF -->
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</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>facelets.VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>CLASSIC</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Allows you to put html comments in your views without the compiler blowing up -->
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</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>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</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_1_2.xsd"
version="1.2">
<application>
<view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
</application>
<!-- Backing Beans -->
<managed-bean>
<managed-bean-name>tableBacking</managed-bean-name>
<managed-bean-class>edu.mayo.ccs.webdataviewer.ui.backing.TableLookupBacking</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
index.xhtml
<!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"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/template.xhtml">
<ui:define name="title">Web Data Viewer</ui:define>
<ui:define name="centerColumn">
<h1>Web Data Viewer</h1>
</ui:define>
</ui:composition>
</html>
As per the comments, you're getting the following exception while configuring Facelets 1.x as per their own docbook:
cannot find fully qualified class: com.sun.facelets.FaceletViewHandler
Apparently JBoss 5.x doesn't ship with Facelets 1.x out the box (could be very good as it's not part of standard Java EE 5). You'd need to provide it yourself in webapp's /WEB-INF/lib. You can get it from the Maven repository among others here. It's the jsf-facelets.jar file.
Note that this file is not required for JSF 2.x as Facelets libraries are bundled in the JSF JAR itself.

JSF web project <h:xxx> tag invisible

I followed a tutorial to make a JSF web project but it's not working, everything in <h : xxx> tag is invisible inside browser such as firefox or googlechrome.
It's suposed to do that :
first you acces index.html, you input your name and press the button.
the bean transmit your name to a JSP and the JSP print
Welcome "your name"
but as said, the input field and button are insivible (they are inside the page code but their length is 0px, setting manually a new width is not working either)
And everything looks normal in eclipse graphical preview tool. :/
my index.html
<?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 - hello.xhtml</h3>
<h:outputText value="test" />
<h:form>
<h:inputText value="#{helloBean.name}"></h:inputText>
<h:commandButton value="Welcome Me" action="welcome"></h:commandButton>
</h:form>
</h:body>
</html>
my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
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_2_5.xsd">
<display-name>webApp</display-name>
<!-- 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>*.html</url-pattern>
</servlet-mapping>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
my bean :
package net.viralpatel.maven;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;
#ManagedBean
#SessionScoped
public class HelloBean implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
resulting HTML:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body bgcolor="white">
<h3>JSF 2.0 Hello World Example - welcome.xhtml</h3>
<h4>Welcome #{helloBean.name}</h4>
</h:body>
</html>
In my pom.xml you can find
myfaces-api 1.2.2
tomahawk 1.1.9
myfaces-impl 1.2.2
jstl 1.1.2
taglib standard 1.1.2
geronimo_servlet_2.5_spec 1.2
jboss-jsf-api_2.0_spec
i'm using a tomcat 7 server
Your mistake is that you used the .html extension instead of .xhtml for the JSF view file. The default JSF suffix is .xhtml.
There are 2 ways to fix this problem:
Tell JSF to use .html as default suffix instead.
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.html</param-value>
</context-param>
Or, rename the index.html file to index.xhtml and fix your web.xml accordingly:
<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>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
Using XHTML has more advantages as to IDE tooling (autocomplete, etc).
in your web.xml, this servlet mapping should not be commented:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

Problem creating my own custom tags(JSF 2.0)

I am learning to create my own custom tags, but i am having a bit of trouble, i cant make this simple app use the tag i created. I think i did everything fine, but i am afraid the paths to the new library i created is wrong. Maybe someone can help me find where my error is and understand the reason of it. This is what i did so far:
1- I created the tag as an xhtml chunk(mybutton.xhtml)
<!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">
<ui:composition>
<h:commandButton type="submit" value="#{buttonSubmitLabel}" />
<h:commandButton type="reset" value="#{buttonResetLabel}" />
</ui:composition>
</html>
2- Then i created an .xml file that will act as the libraries where all my custom tags are indexed(mytagsconfig.taglib.xml)
<?xml version="1.0"?>
<facelet-taglib 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-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://mytags.com/facelets</namespace>
<tag>
<tag-name>mybutton</tag-name>
<source>mytags/mybutton.xhtml</source>
</tag>
</facelet-taglib>
3- I tried to register my new library in the web.xml, so i can use it
<?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>CHAPTER 5 Creating your own Custom tags</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>*.xhtml</url-pattern>
</servlet-mapping>
<!-- REGISTERING A CUSTOM TAG INTO JSF APPLICATION -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/mytagsconfig.taglib.xml</param-value>
</context-param>
</web-app>
4- And last i try to use the tag in some page(In my case inside a component that is inserted in a template)
<!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"
xmlns:mytags="http://mytags.com/facelets">
<ui:composition template="WEB-INF/templates/masterLayout.xhtml">
<ui:define name="pagetitle">
Defining custom tags
</ui:define>
<ui:define name="content">
Defining custom tags is a 3 step process:
<ul>
<li>Use ui:compisition to create some content.(Custom tags are stored in WEB-INF/customtags)</li>
<li>Declares the custom tag in a tag library descriptor into the WEB-INF folder(Example: mycustomtags.taglib.xml).</li>
<li>Register the tag library descriptor in the web.xml.</li>
</ul>
<!-- Here should go a call to the new created tag -->
<mytags:mybutton buttonSubmitLabel="Submit" buttonResetLabel="Reset" />
</ui:define>
</ui:composition>
</html>
This is my folder structure:
****Update****
When i build i see the index.xhtml page, but the custom tag is not there(I dont see the 2 buttons)
Your taglib declaration in web.xml does not point the right filename.
You said that you've created a /WEB-INF/mytagsconfig.taglib.xml, but you've declared it in web.xml as /WEB-INF/mytags.taglib.xml instead. Fix it accordingly.
Not directly related to the problem, but consider upgrading to JSF/Facelets 2.0 compatible taglib root declaration and web.xml context param name.
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
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-facelettaglibrary_2_0.xsd"
version="2.0">
<!-- Taglib config here. -->
</facelet-taglib>
and
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/mytagsconfig.taglib.xml</param-value>
</context-param>

JSF tags not rendered [duplicate]

This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 6 years ago.
I am new to JSF, but my JSF tags are not rendered in xhtml file,
i tried out every possible solution, but problem is not solved
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>JSFProject</display-name>
<welcome-file-list>
<welcome-file>JSFProject/index.html</welcome-file>
<welcome-file>JSFProject/index.htm</welcome-file>
<welcome-file>JSFProject/index.jsp</welcome-file>
<welcome-file>JSFProject/default.html</welcome-file>
<welcome-file>JSFProject/default.htm</welcome-file>
<welcome-file>JSFProject/default.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
my example.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Example</title>
</head>
<body>
<h:form>
Some random data: <h:inputText/><br/> <!-- Textfield ignored -->
Some other data: <h:inputText/><br/> <!-- Textfield ignored -->
</h:form>
</body>
</html>
I had spend 3 days to figure out the problem, any help will be welcome
The symptoms of the JSF components not being parsed at all indicates that the FacesServlet hasn't run. This will happen when the request URL doesn't match the url-pattern of the FacesServlet as definied in web.xml. This would mean that the actual url-pattern of the FacesServlet isn't *.xhtml at all. Are you looking into and editing the right web.xml you think you are? Is the right web.xml been deployed with the webapp into the servletcontainer?
I had the same problem, I fixed this by updating below as:-
Already Martin had mentioned in the above. Thanks.
web.xml
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</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>*.faces</url-pattern>
</servlet-mapping>
faces-config.xml
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
Try:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Example</title>
</head>
<body>
<f:view>
<h:form>
Some random data: <h:inputText/><br/> <!-- Textfield ignored -->
Some other data: <h:inputText/><br/> <!-- Textfield ignored -->
</h:form>
</f:view>
</body>
</html>
I've included the JSF <f:view> tag
Man, you haven't set the javax.faces.DEFAULT_SUFFIX context parameter. The default for jsf is jsp, so jsf will search for example.jsp instead of example.xhtml. Basically JSF replaces the extension of the resource requested with the javax.faces.DEFAULT_SUFFIX.
Use the following and it will work:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
Do you have faces-config.xml in place that declares Facelets as view handler?
<?xml version="1.0"?>
<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_1_2.xsd" version="1.2">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
Don't forget about javax.faces.DEFAULT_SUFFIX parameter to be set to .xhtml as mentioned above.
Add the following in your web-inf/lib :
jsf-api-2.0.9.jar
jsf-facelets-1.1.14.jar
jsf-impl-2.0.4-b09.jar
jstl-1.2.jar
without jsf-facelets*.jar, you won't be able to render the jsf view.
And, following should be in your web.xml :
<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>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Without above two url-pattern, tomcat won't be able to map .xhtml file properly.
And, 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>

Categories