By: Abinaya in JSF Tutorials on 2007年10月06日 [フレーム]
Information about the view components in the web application and information about how control flows through the application is contained in a special configuration file named faces-config.xml, shown in Listing below. Although faces-config.xml can contain a lot of information about a web application, for this example we need it to do only two things: identify the flow of control from searchForm.jsp to searchResults.jsp, and identify the JavaBean used by the application.
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/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/searchForm.jsp</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>/searchResults.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>flight</managed-bean-name>
<managed-bean-class>com.apress.projsp.FlightSearch</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
Thefaces-config.xmlfile identifies the JavaBeans used by the web application in the <managed-bean> element. You will have a <managed-bean> element for every JavaBean used by your web application. The <managed-bean> element in Listing above contains three subelements:
The faces-config.xml file is also used to tell the controller how to navigate through the application. Navigation flow is specified in <navigation-rule> elements. Our example needs only one element. In general, a <navigation-rule> element identifies the start page, a condition, and the page to navigate to when the condition occurs.
In our example, the start page is searchForm.jsp. If the page request is submitted with an outcome of submit, control is transferred to searchResults.jsp. Looking at Listing, you can see that the <commandButton> element has an action of submit; when the button is clicked and the form is submitted, this action matches the <from-outcome> of the <navigation-rule>. The <navigation-rule> element also includes an empty <redirect> element. With this element, the response is created by causing the browser to redirect to the searchResults.jsp page, which also updates the address bar in the browser. Without this element, the response is still created correctly and sent to the browser, but the address bar of the browser will not be updated and will still display the address for the originating page.
We need just one final piece for our web application. In this example, our default page will be a standard HTML page that redirects to the correct URL for a JSF application. Listing below shows index.html.
index.html
<html>
<head>
<meta http-equiv="Refresh" content= "0; URL=searchForm.faces"/>
</head>
</html>
You can see that that the redirect URL is searchForm.faces. However, there is no component in our application named searchForm.faces. How then does the web application know which page to serve? All requests that are JSF requests are directed to the controller for the application, which is a servlet supplied as part of the JSF reference implementation.While deploying this example, you will specify that all URLs of the form *.faces should be sent to the controller servlet. This servlet then converts the searchForm.faces request to searchForm.jsp, processes the JSP page, and sends the response to the browser.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JSF )
How to open a new browser window from my JSF page?
Struts Vs JSF (A comparison of Struts against JSF)
Calling Multiple Listeners in JSF
Accessing Context Data in Beans using JSF
faces-config.xml to DirectTraffic in the JSF Application
JSF - TreeNode.setID gets IllegalArgument Exception
Servlet error : java.lang.IndexOutOfBoundsException (JSF RI 1.1_01: IndexOutOfBoundsException)
<convertNumber> and <convertDateTime> in JSF
Controlling Page Navigation in JSF - Static and Dynamic Navigation
Latest Articles (in JSF)
Struts Vs JSF (A comparison of Struts against JSF)
Calling Multiple Listeners in JSF
<convertNumber> and <convertDateTime> in JSF
faces-config.xml to DirectTraffic in the JSF Application
JSF - TreeNode.setID gets IllegalArgument Exception
Servlet error : java.lang.IndexOutOfBoundsException (JSF RI 1.1_01: IndexOutOfBoundsException)
How to open a new browser window from my JSF page?
Accessing Context Data in Beans using JSF
Install and Deploy JBoss Application Server
Controlling Page Navigation in JSF - Static and Dynamic Navigation
Struts Vs JSF (A comparison of Struts against JSF)
Calling Multiple Listeners in JSF
<convertNumber> and <convertDateTime> in JSF
faces-config.xml to DirectTraffic in the JSF Application
JSF - TreeNode.setID gets IllegalArgument Exception
Servlet error : java.lang.IndexOutOfBoundsException (JSF RI 1.1_01: IndexOutOfBoundsException)
How to open a new browser window from my JSF page?
Accessing Context Data in Beans using JSF
Install and Deploy JBoss Application Server
Controlling Page Navigation in JSF - Static and Dynamic Navigation
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate