JSF tags not rendered [duplicate]
Asked Answered
F

6

7

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

Febricity answered 25/7, 2010 at 11:15 Comment(5)
What URL are you trying to access?Ruthi
url is: localhost:8080/JSFProject/exmaple.xhtml server is Jboss 5.1.0 GAFebricity
sorry the url is localhost:8080/JSFProject/example.xhtmlFebricity
what is rendered? get the HTML source of the page.Sink
include the <f:view> tag and see what happensGuimar
S
17

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?

Schleicher answered 26/7, 2010 at 2:45 Comment(0)
O
3

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>
Oneself answered 21/9, 2011 at 19:50 Comment(1)
That only applies to JSF 1.x with Facelets 1.x. OP's problem symptoms and the presence of javax.faces.PROJECT_STAGE param indicates that he was using JSF 2.x wherein the FaceletViewHandler and javax.faces.DEFAULT_SUFFIX is unnecessary and you can map the FacesServlet just on *.xhtml instead of *.faces. Mapping FacesServlet on *.xhtml would in JSF 1.x have resulted in an infinite forward loop. I believe after all that his faces-config.xml was of incorrect version.Schleicher
G
1

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

Guimar answered 25/7, 2010 at 16:52 Comment(1)
This won't help. He's using Facelets where f:view isn't mandatory, not JSP. And even then, if he was using JSP, a missing f:view would have caused JSF to throw an IllegalStateException when it encounters a component without a parent UINamingContainer component during parsing.Schleicher
P
0

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>
Phrygia answered 27/7, 2010 at 6:29 Comment(3)
This is true when you're using JSF 1.2 instead of 2.0, but it would have resulted in a 404 when passed through FacesServlet, not in an unparsed page. So it can only mean that it's not been passed through FacesServlet.Schleicher
@Schleicher Yes, but he hasn't told us which version of JSF is using. Also he hasn't clarified what he means by rendered. Maybe he gets a 404 and he hasn't told us. This is what I consider.Phrygia
not that it would still matter, but if you change the version in faces-config to 2.0 from your original 1.2 i bet it will workKetty
G
0

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.

Gower answered 27/7, 2010 at 12:35 Comment(0)
S
0

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>
Slingshot answered 17/7, 2013 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.