Java Development Wonderful Tutorial: JSF Series (1) Source: PConline Editor: chenyong
[03-10-21 15:34] Author: fpwang / Matrix.com
Java Server Faces (JSF) technology provides standard programming interface APIs and tag libraries for developers based on network user interface. The Apache Struts Framework Author Craig Mcclanahan assists in leading Sun's JSF project. This allows the project to be easily transplanted from the popular Apache to the JSF standard. Just like the Struts framework, JSF defines a set of JSP tags that can generate an HTML form element that is bound to the Javabean property. From the perspective of the application developer, both frameworks are very similar, but JSFs may get more support. Because JSF is the standard of Java. In the future, there may be all J2EE application servers need to support JSF (Java Server Faces).
Sun Inn the free download of Java Web Services Developer Pack 1.2 (http://java.sun.com/webservices/downloads/webservices), including JSF (JSF Specification Version 1.0, public review Reference implementation of Draft 2) (Early Access 4 - EA4). The EA4 version implements many new features: action, beans management and navigation rules. This article will focus on these new features and show how to get benefits from JSF development to establish a form, confirm user input, and bind user interface components to JavaBeaN properties.
This article contains a network application consisting of four main parts:
1. JavaBean class (PBean.java), saving some text as a data model and related properties: font, size, color, placement position, etc.
2. Based on JSF's form (edit.jsp), users can assign values for JavaBean attributes;
3. Java class (PBUILDER.JAVA), generate an HTML page program with a given text;
4. JSP page (View.jsp) shows the generated HTML page.
Note:
Source code download address: http://www.onjava.com/onjava/2003/09/03/EXAMPLES /USINGJSF-SRC.ZIP
Documentation
Original: Introducing JavaServer Faces (http://www.onjava.com/pub/a/onjava/2003/07/30/JSF_INTRO.HTML)
Translation: http://www.matrix.org.cn/forum_view.asp?forum_id=14&view_id=658
JavaServer Faces (or JSF) is a new development trend in the development of the server. It allows you to make your more easily design, your program can easily maintain, and may even make your work more interesting. Budi Kurniawan showed us JSF technology to explain why JSF is so useful and whether it has implemented the functions committed.
Figure 1: Form based on JSF
Making a JSF form
Handling an HTML form is the most common task when you develop network applications. A good frame can save a lot of development time, because many daily program operations can be done automatically or to minimize only need to be done in the XML file. This is also possible to simplify network development using the JSP tag library. The Java Server Faces framework provides JSP tags for describing the form, managing form status, confirming user input, and error, binding user interface components with JavaBeaN properties, and many other functions that improve development efficiency. JSF also has a rich programming interface to establish a custom user interface (UI) component, custom verification class (verifier Validator), and server event listener. JSF contains two types of tag libraries to name the JSF core library and HTML base library, respectively. The former provides normal markers and some tags for registering the validator in the user interface components and event listeners. The latter includes a JSP tag for describing user interface components, such as buttons, text domains, check button, list, and more. File edit.jsp creates a form with these tags. The standard prefix of the two tag libraries is F and H, and the front of the edit.jsp file is defined:
<% @ taglib prefix = "f" URI = "http://java.sun.com/jsf/core";%> <% @ Taglib prefix = "h" uri = "http://java.sun.com / jsf / html ";%>
The above JSP code generates the following HTML pieces: