Resources: instance http://www.crossbar.info/ myface http://www.myfaces.org/ Translator: FPWANG) JAVA Server Faces (JSF) technology provides Java developers based on network user interface Standard programming interface API and tag library. The Apache Struts frameworks Assist 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 location, etc. 2. Based on JSF Form (edit.jsp), user can assign a value for JavaBean attribute; 3. Java class (pbuilder.java), generate HTML page programs with a given text; 4. JSP page (view.jsp), Display the generated HTML page. Note: Source code download address: http://www.onjava.com/onjava/2003/09/03/EXAMPLES/USINGJSF-SRC.ZIP related 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 server program Develop a new trend. 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: JSF-based form making JSF form When you develop network applications, the HTML form is the most common task. 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";%> tag is a container tag, must contain all the same pages JSF tag. This tag does not generate any HTML content, but it triggers the internal mechanism of JSF. tag generates an HTML element
Class PBEAN follows the JavaBean specification to implement the corresponding GET and SET methods for its properties (text, size, font, color, placement position, bold, slope, underscore). The user of each application of JSF creates an instance of a PBean, which is stored in a JSP session (session) and specifies the ID in the XML format profile named Faces-Config.xml. JSF will also initialize the property value of the JavaBean instance based on the data provided by the Faces-Config.xml file. The XML file may also contain other JSF configuration parameters, such as navigation rules, we will introduce later in the following chapters.
The following XML program is broken contains the JavaBean managed by JSF: XML Version = "1.0"?> ......... PBean managed-bean-name> com.devsphere.An-scope> session management-bean-scope> session management-bean-scope> session management-bean-scope> session managed-bean-scope> < Managed-proteTy> text profy-name> management-property> size profy-name> 3 < / value> managed-protety> font profy-name> arial value> Courier New value> value> managed-protety> Color Property-Name> green value> management-property> align profoyal-name> left value> management-property> < Managed-proteTy> bold property-name> false value> management-property> Italic <
/ Property-Name> true value> management-protety> underline printy-name> false value> managed-property> managed-bean> faces-config> The management bean created by JSF can be stored within the request (Session) or application according to the value of the element. The value of element can be empty. If an object already specifies the ID and register, JSF does not establish a JavaBean instance within a given range. User Interface Components and Verify Files Edit.jsp In elements in edit.jsp contain multiple user interface components, we will introduce in detail later. The HTML code of each component is generated by the JSF component tag, for example: , which may also contain other JSF tags, such as: tag, the tag makes the JSF to confirm that the user entered information. . Handling the components entered by the user use attributes VALUEREF = "pBean.property" binds with the Javabean property. JSF Get and Set Management Bean Properties is already introduced earlier. Some JSF component tags do not handle any user input. For example can be used to output a value of the text or JavaBean read-only properties. Each component has a unique ID, ID can be specified in the ID attribute or automatically generated by JSF. The user interface component to be verified requires the ID attribute to verify that the error can be displayed together with the . Figure 2: Verifying the text field of the error text Domain Text Area JSF form allows the user to generate the PBUILDER.JAVA and display some text paragraphs displayed by View.jsp. Edit.jsp shows a label determined by and use to generate
......... h: Form> f: Use_faces> The above JSP code generates the following HTML pieces:
text:
tag is to make the verifier confirms the number of users entered within a given range. If the range is exceeded, the verification error is reported to the user, and the error message is generated by . ...........
h: input_number> ......... h: form> f: Use_faces> The above JSP code generates the following HTML pieces:
.........
size: [1-7]
......... form> The single line text domain is set to size, the type is shaped (int). The value of the value attribute in the size is the initial value indicating the generated HTML form digital input area. Assume that no verification error occurs, when the JSF receives user inputs that contain new JavaBean size attribute values, JavaBean will be refreshed. The size property of the tag is the character length (2) defining a single line text domain, and does not have other operations for the JavaBeaN property.
Public class pBean Implements java.io.serializable {........ private int size; public int getsize () {return size;} public void setsize (int size) {this.size = size;}. .......} In addition to tagged, JSF also provides several validator tags: l L L L The last one is a general-purpose tag, which can be used to register your own custom validator in the user interface components. You can also create your own verifier tag library. List List Box and Tag Generate HTML Elements