Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Subj : New to JSF : How to change the JSF pages file suffix ?

843844Feb 14 2010 — edited Feb 14 2010
Hi
In a JSF application, how do you change the suffix of JSF files from the default suffix of .jsp, to eg .jsf , eg index.jsf and welcome.jsf ?

I'm new to Java Server Faces, and have just done the Hello World from the book Core JavaServer Faces by David Geary, 2nd ed. This worked fine. This just consists of 2 JSF files index.jsp and welcome.jsp, plus the config files web.xml and faces-config.xml, plus a Java bean to store the entered name. File index.jsp is just a form with a name and pswd text field. Upon pressing the Submit button it returns the contents of welcome.jsp, acc to the nav rule, ie some Welcome text plus your entered name. The full code that works is shown below. To show the first page I enter the URL http://localhost:8080/login/index.faces .. .. the app is all in login.war, and the .faces suffix is defined in the web.xml file). As I understand the FacesServlet servlet strips off the .faces and loads the file of the same name but with the default .jsp suffix.

I'm working with the JEE 5 + Glassfish v.2.1 on Windows, browser Firefox

I tried to change the .jsp suiffix as follows , but it didn't work .. I wanted to change files index.jsp and welcome.jsp to index.jsf and welcome.jsf. I tried adding in the default suffix definition to web.xml, so in total we now have :

<web-app .. .. >

<context-param>
<param-name> javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsf </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>

</web-app>

Then I changed the actual suffices to index/welcome.jsf, and changed the names to index/welcome.jsf in the nav rule ...

But all this did not work , or rather partially worked. Upon entering URL : http://localhost:8080/login/index.faces the Framework picked up the right file index.jsf, and showed it back to the browser, but did not interprete the JSF tags, but just passed back the original file contents without alteration.

Any ideas what I am doing wrong ?

Any help would be great

Eddie


Original &lsquo;Hello World' files .. this works : *

The index.jsp page

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td>
<h:inputText value="#{user.name}"/>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<h:inputSecret value="#{user.password}"/>
</td>
</tr>
</table>
<p>
<h:commandButton value="Login" action="login"/>
</p>
</h:form>
</body>
</f:view>
</html>

web.xml

<?xml version="1.0"?>
<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_2_5.xsd"
version="2.5">

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

faces-config.xml

<?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">

<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.corejsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>

welcome.jsp

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h3>
Welcome to JavaServer Faces,
<h:outputText value="#{user.name}"/>!
</h3>
</h:form>
</body>
</f:view>
</html>


UserBean.java

package com.corejsf;

public class UserBean {
private String name;
private String password;

// PROPERTY: name
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }

// PROPERTY: password
public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; }
}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2010
Added on Feb 14 2010
1 comment
492 views