The first article of the "Web Tier to Go With Java EE 5" series summarizes new features in JavaServer Pages (JSP) 2.1 technology. As that article describes, the biggest contribution of JSP technology is better alignment with JavaServer Faces technology, which was accomplished by unifying the two expression languages (ELs). Alignment with the JSP framework is also one of the more important achievements of JavaServer Faces 1.2 technology, developed through JSR 252. In addition to these changes, JavaServer Faces technology contributes a host of other significant ease-of-use features. This article briefly describes the more substantial ones, which include the following:
The Preface section of the JavaServer Faces specification provides a complete list of new features. At the center of the incompatibilities between the JSP and JavaServer Faces technologies was the difference between the page life cycles that they support. As the previous article explains, the JSP specification supports a single render-and-response life cycle during which the elements in the page are executed in the order they appear, and the page is rendered immediately. The JavaServer Faces technology life cycle, on the other hand is divided into several phases, during which a component tree is created, the components' data is processed, and the components are rendered to the page. Therefore, a JavaServer Faces page is not necessarily rendered immediately after it is executed. As a result, the use of JavaServer Faces components in JSP pages sometimes caused content to be rendered in the wrong order, component state to be lost, or other problems to occur. The article summarizing new features in JSP 2.1 technology touched on some of these issues. This article gives you more detail on what has changed in JavaServer Faces technology to foster alignment between the two technologies:
First-Class Support of JSTL's
As described in the article describing new features in JSP technology, one benefit of unifying the EL in the entire Java EE web tier is that iterating tags such as JSTL's
Without the unified EL, this coordination would not be possible. Improvements in Tree Creation and Content Interweaving As documented by Hans Bergsten in his article about the use of JavaServer Faces technology with JSP pages, mixing JSP code with JavaServer Faces tags sometimes yielded unexpected results. For example, in the following code, the value of the JavaServer Faces output text component
However, these two lines are reversed in the code's output. What caused this problem? The JavaServer Faces implementation depended on the JSP rendering engine to render the component tree. Because JSP technology immediately executes and adds static text to the response, whereas the children of the Problems such as this and others mentioned in Hans Bergsten's article have been fixed in JavaServer Faces 1.2 technology. The solution involved changing how the component tree is created and how various kinds of content are processed and rendered. The most important changes are the following:
The upcoming article in the "Web Tier to Go With Java EE 5" series provides a more detailed discussion of the improvements in tree creation and content interweaving, which now make it possible to mix JavaServer Faces component tags with other JSP code. Deprecation of the JavaServer Faces EL in Favor of the Unified EL As the previous article in this series explains, the ELs of both the JSP and JavaServer Faces technologies are consolidated into the unified EL. This means that the JavaServer Faces EL is now deprecated. Those of you who had built JavaServer Faces applications prior to the introduction of the unified EL can be assured that your applications are completely backward-compatible.
However, in order to take advantage of the unified EL's features, you will need to change your custom components and custom tags. Migrating to the unified EL primarily involves changing To get more details on migrating to the unified EL, please see the article "Unified Expression Language." The most-improved feature of JavaServer Faces 1.2 technology is the ability to add custom messages to a JavaServer Faces application. The improvements in this area include the following:
Set of Standard Converter Messages Prior versions of JavaServer Faces technology included a set of standard error messages to accompany the standard validators. Version 1.2 also includes a set of messages for the standard converters. To see the entire list of messages, refer to section 2.5.2.4 of the specification. New
In most cases, a standard error message meets your needs. When it does not, you can override it with your own custom messages by using the
This new feature allows you to override a message when you want to. For example, let's say you are using the length validator on the These attributes accept literal values as well as value expressions, as do most JavaServer Faces tag attributes. Therefore, you can use a value expression to reference a message contained in a resource bundle, as this example shows:
As you might have guessed, the value of an input component's Because of this feature, page authors can now provide error messages that are more tailored to the component using it. Thus, the user can more easily determine the source of the error. A New
Another feature that helps users decipher error messages is the new
Say that you have a
The New
Prior to version 1.2 of JavaServer Faces technology, page authors used the
A new, more efficient way of loading resource bundles involves registering a resource bundle with the entire application by using a
The
In this example,
With the new Version 1.2 of JavaServer Faces technology contains two major changes to the state-management facility. One change involves rectifying problems with application state becoming disoriented when an application uses multiple frames or windows. The other change is providing the option to secure state on the client. The cause of the disoriented application state in multiframe or multiwindow applications was that these multiple logical views within the root view often would have duplicate IDs and would therefore confuse the state-management facility. Several changes to the state-management API in version 1.2 solve this problem.
First, each window or frame within a view now has a unique ID, which is a combination of the view root's ID and a random number that is saved into a hidden field in the form associated with the window or frame. The
Also during the life cycle's render response
The other major improvement to state saving allows you to encrypt client-side state before including it in the rendered markup that is sent to the client. You can choose to encrypt client-side state by using the
The password that you provide is used to generate keys and cyphers for encryption. If this environment entry is not present in your configuration file, no encryption will occur. JavaServer Faces technology uses an algorithm to generate client IDs for components included in a form. In prior versions, these components' client IDs looked like this:
Page authors had the option of specifying a client ID for a form component and for any of the other components included in the form. If the page author did not specify a form's client ID or a component's client ID, the implementation would generate them automatically. Earlier versions of JavaServer Faces technology did not specify this algorithm well enough for developers to understand how it worked. Furthermore, a custom component or renderer class had no easy way to determine whether the page author had set a component's client ID or the implementation had automatically generated it. Finally, an author of custom renderers might not be able to change the name of the form for one reason or another but might still need to reference its components with JavaScript technology.
This release of JavaServer Faces technology includes a more explicit explanation of the algorithm that generates the client ID. You can find it primarily in the API documentation for
In addition to the
To illustrate this tag's usefulness, let's suppose you have a
When the user clicks the button represented by the
If you are familiar with JSTL, you know that the
In this case, the Conclusion
This article demonstrates that JavaServer Faces 1.2 technology offers plenty of valuable new features and includes solutions to many long-standing problems. We encourage you to give version 1.2 a try. If you have any questions or comments, please write or join us at the forum or in our public IRC chat room. In the meantime, watch for the next article in the series, which will describe resource injection on the web tier. For More Information
Web Tier to Go With Java EE 5: Summary of New Features in JSP 2.1 Technology, Part 1 in the series |
| ||||||||||||||||||||||||||||||||||||||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||