Search your topic in Java2share
Home > FAQs
eXTReMe Tracker

Java Server Faces FAQs

Untitled Document

Q5. How the components of JSF are rendered? An Example

In an application add the JSF libraries. Further in the .jsp page one has to add the tag library like:

<%@ taglib uri="" prefix="f"%>
<%@ taglib uri="" prefix="h"%>
Or one can try XML style as well:
<?xml version="1.0"?>
<jsp:root version="2.0" xmlns:jsp=""

Once this is done, one can access the JSF components using the prefix attached. If working with an IDE (a.k.a Integrated Development Environment) one can easily add JSF but when working without them one also has to update/make the faces-config.xml and have to populate the file with classes i.e. Managed Beans between
<faces-config> </faces-config> tags

Q6. How to declare the Navigation Rules for JSF?

Navigation rules tells JSF implementation which page to send back to the browser after a form has been submitted. For ex. for a login page, after the login gets successful, it should go to Main page, else to return on the same login page, for that we have to code as:


from-outcome to be match with action attribute of the command button of the login.jsp as:

<h:commandbutton value="Login" action="login"/>
Secondly, it should also match with the navigation rule in face-config.xml as

In the UI component, to be declared / used as:
<h:inputText value="#{}"/>
value attribute refers to name property of the user bean.

Q7. How do I configure the configuration file?

The configuration file used is our old web.xml, if we use some IDE it will be pretty simple to generate but the contents will be something like below:

<?xml version=&quote;1.0&quote; encoding=&quote;UTF-8&quote;?>
<web-app version=&quote;2.4&quote; xmlns=&quote;;
xsi:schemaLocation=&quote; http://java.sun.<context-param>
<servlet-name>Faces Servlet</servlet-name>
<servlet-name>Faces Servlet</servlet-name>

The unique thing about this file is ?servlet mapping?. JSF pages are processed by a servlet known to be part of JSF implementation code. In the example above, it has extension of .faces. It would be wrong to point your browser to http://localhost:8080/MyJSF/login.jsp, but it has to be http://localhost:8080/MyJSF/login.faces. If you want that your pages to be
with .jsf, it can be done with small modification :-),

<servlet-name>Faces Servlet</servlet-name>

Q8. What is JSF framework?

JSF framework can be explained with the following diagram:
As can be seen in Figure 1, JSF interacts with Client Devices which ties together with
presentation, navigation and event handling and business logic of web tier model. Hence JSF is limited to presentation logic / tier. For Database tier i.e. Database and Web services one has to rely on other services.