Chapter 1 brief description of JSF
[Thinker-Yhm1218@hotmail.com]
First, what is JSF
JSF JavaServer Faces is a new technique for architecture J2EE application user interface, suitable for applications based on MVC architecture.
The main functions of JSF technology are:
Managed Bean Tool Verification Tool Rich and Scalable Component Library Inserted Rendering Toolkit The Navigation Speed Route Reserved Application Status Conversion Model Responsible for Specific User Event Responsive
This article will describe the above functions through the CNJSF application, you need to understand this article, you need to understand the Web development, servlet, jsp, javabeans, and label libraries.
Second, the working principle of JSF
The JSF application is essentially a servlet or Java Server Pages (JSP) application that runs in a container compatible with Java (TM) 2 Platform, Enterprise Edition (J2EE (TM) Platform). However, JSF does not require JSP pages in the application, you can freely choose to use Servlets or other template technology. If you really use JSF to the JSP container, you will benefit from the built-in JSF core and HTML component library through the JSF customer component label. The JSF component represents a web control of text fields, forms, buttons, tables, check boxes, and the like.
When using JSF to create a JSP page (as MyForm.jsp in Figure 1-1), a component tree is created in the memory of the server (the web container in Figure 1-1), each component tag corresponding to the tree A UIComponent instance (MyUI in Figure 1-1). The framework uses component trees to process applications (as http requests in Figure 1-1) and create a presented response (as HTTP Resonse in Figure 1-1). When the user generates an event, for example, click on a button, the JSF lifecycle is processed by the event and generates an appropriate response. This is a common example of a form for most GUI programming. Whenever the user does anything, if you click the button or submit a form, there is an event generation. The event message is then transmitted to the server via HTTP. At the server side, it is a Web container that is configured with a special servlet called Faces Servlet. Faces servlet (javax.faces.webapp.facesservlet) is an engine for all JSF applications. Each JSF application has a separate Faces Servlet in a web container.
Facesservlet is the entry point entry to the JSF framework. It processes the request to handle life cycles and serve as a front-end controller. JSF also has the concept of context that holds important request information. The context object is called FaceScontext (javax.faces.context.facescontext). Each stage of the JSF lifecycle is modified and is valid for each request.
The background processing of the Faces Servlet is quite complicated. However, you don't have to understand these details, just remember that the Faces Servlet creates a component tree for the JSP page, and the control of the component tree is correspondingly. Faces Servlet knows how to create a component tree because it has accessed all JSP pages in the current application. Faces Servlet also creates an EVENT object and passes it to all registered listeners. You can get the components of this page by FacesContext corresponding to the current request.
UI running schematic in the server (Figure 1-1)
Third, a simple JSF application (a Simple JSF Application)
1. Steps to create a JSF application
Developing a simple JSF application typically requires the following four steps: u Create a page (usually a JSP page), encapsulate HTML element U in the application resource profile with JSF Components User Navigation Udrite Beans to keep users Enter the status of the component data. u Add Managed Bean description in the application resource profile
The above four steps can be carried out simultaneously or in any order. However, different open
It is recommended to keep in touch between senders. For example, page author needs to know the name of the object to be accessed by page.
Below, we will appreciate the above content through a simple application (Hello World).
2. Run the application
[Need this application engineering package to send email to YHM1218@163.com]
This application is a simple user registration form commit program. In order to run this application, you need to prepare Tomcat 5.0 and JSF1.1 (included in Java Web Services Developer Pack (JWSDP) 1.4). In order to make this application work normally, there are several JAR files, including JSF standard implementation and other class libraries. If you have a JWSDP 1.4, you can find these files you want in the JSFLIB directory. Copy these .jar files into the web-inf / lib directory. Here is the list of the entire .jar and .tld file:
JSF-API.JAR includes classes with Faces Servlet and other related javax.faces packets, JFS-IMPL.jar is JSF for JSTL.jar Standard.jar Commons-beanUtils.jar Commons-Collections.jarcommons-Digester.jar Commons- Logging.jar
Of course, if you are using JBuilder 2005, then you only need to open this program in JBuilder 2005, edit the project properties, set server for Tomcat5.0, recompiling the project, and start Tomcat5. 0. OK, you can now access http: // localhost: 8080 / web / index.faces. [JBuilder 2005 integrated JSF]
3, brief analysis of applications
(1) Creating a page (CREANG THE PAGES)
There are four JSP pages in this application.
INDEX.JSP ---- Welcome page
<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ Taglib Uri = "http://java.sun.com/jsf/core" prefix = "f"%> <% @ Taglib URI = "http://java.sun.com/jsf/html" prefix = "h"%>
The JSP page provides the UI, JSF provides two JSP label libraries (in subsequent chapters, we will explain in detail in this area), which exhibit components to page designers. You can customize these components or create your own components. Standard components are presented as basic HTML4.01 components that make JavaScript absolutely minimal, ensuring that your page is displayed in all browsers.
1. To use the built-in JSF label library containing components, you need to include the following instructions in the JSP page.
<% @ Taglib Uri = "http://java.sun.com/jsf/core" prefix = "f"%> <% @ Taglib Uri = "http://java.sun.com/jsf/html" prefix = "h"%>
2, Note Your JSF page requires all JSF tags to be included between the
3,
# 公 变 c c = Hello Worldcnjsf.welcome.title = :: CNJSF Net Welcome :: cnjsf.reg = Register CNJSF.USERNAME = User name cnjsf.password = password cnjsf.success = Register success cnjsf.failure = Registration failed CNJSF.Reback = Return
ApplicationResources_zh.properties
# / u
516C / U5171 / U53D8 / U91CFCNJSF.WELCOME.MESSAGE = Hello Worldcnjsf.welcome.title = :: CNJSF / U
7f51 / u6b22 / u8fce / u
60A8 :: CNJSF.REG = / U6CE8 / U
518ccnjsf.username = / u7528 / u6237 / u540dcnjsf.password = / u5bc6 / u7801cnjsf.success = / u6CE8 / U
518C / U6210 / U
529fcnjsf.failure = / u6CE8 / U
518C / U5931 / U8D25CNJSF.REBACK = / u8fd4 / u56de
Bind the information of the resource file to the JSF tag:
This code is translated into html is: registration span>
4,
Translated into html is: