Adding Ajax to JavaServer Faces Technology With Dynamic Faces
Article
Adding Ajax to JavaServer Faces Technology With Dynamic Faces
This article shows how to use Project Dynamic Faces, included in the new Sun Web Developer Pack, to add first-class Ajax support to your JavaServer Faces technology-based application.
Beginning with an existing sample application, Virtual Trainer, from the book that the article's author wrote with Chris Schalk, JavaServer Faces: The Complete Reference, this article will show you how to add Ajax behavior to two of that application's pages. This example will illustrate two usage patterns for Project Dynamic Faces and also provide a springboard for discussing the Ajax techniques that Dynamic Faces employs.
First, this article will go through the Virtual Trainer application and call out the places where you will add Ajax features.
The application's welcome page contains two links at the upper right: Register and Login. The Sign Up Today! link at the bottom of the page points to the same page as the Register page. Click Register.
The screen capture in Figure 1 shows the non-Ajax version of the registration page. As you can see, this is a garden-variety JavaServer Faces technology-based page. Fill out the form but use
jake
for the Userid text field, and submit the form.
Once you get past the validation errors, you will see the message Userid jake already exists! Please choose another. Wouldn't it be nice if there were a button next to the Userid field that would allow the user to fire an Ajax request off to the server, sending only the user ID and checking only whether that user ID is available? With a few lines of code, you can create this functionality. Now click the Login link in the application, and use jake as both the user ID and the password. Once logged in, you will see a table of training events, as shown in Figure 2. Choose one training event by clicking the Select link at the right of the desired row.
Listing 2 shows a diff , a file comparison showing the difference between two versions of the same file, of the register.jsp file before and after the changes that this article discusses. As you can see, the author of this article added or changed only 11 lines. Listing 2: diff of Old and New register.jsp Files
Listing 3 shows this new method. This is a plain-old JavaServer Faces ActionListener method. It does not do anything specifically Ajax-related, but because you are using Dynamic Faces, it will be invoked by Ajax. On line 2 of Listing 3, you get the value of the Userid field. Note that this component is bound with a JavaServer Faces component binding, as shown on line 87 of Listing 1. For more detail on component bindings, see the book JavaServer Faces: The Complete Reference. Because you are running the full JavaServer Faces life cycle, you know that the value has been validated and converted according to any validators or converters attached to the component. Line 3 of Listing 3 uses a class specific to the Virtual Trainer application, UserRegistry , which provides a handy method, userIdAlreadyExists . You simply pass the user ID from the text field to this method and store a message in request scope, as shown on lines 4 through 14 of Listing 3. Because this application is already internationalized, you will use the ResourceBundle for the application to get the message. Note that you are passing the current locale from the ViewRoot into the ResourceBundle.getLocale() method. This ensures that the language settings sent by the browser are correctly handled with respect to the supported localizations for this application. Sun Web Developer Pack Tutorial. Project Dynamic Faces reference materials. Briefly, putting components within an Ajax zone causes them to be imbued with Ajax behavior such that clicking on the element will cause an Ajax transaction to the server, allowing just those components within the zone to update themselves by way of Ajax. The Sun Web Developer Pack Tutorial describes how to make action in one zone cause a reaction in another zone, all by way of Ajax. Source code for this bundle Original source for the virtual trainer application Sun Web Developer Pack Tutorial |
相关推荐
Chapter 9: Developing with JavaServer Faces Technology 159 Backing Beans 159 Writing Bean Properties 162 Writing Backing Bean Methods 170 Using Bean Validation 174 Chapter 10: Java Servlet ...
chm格式的,非常好的一本书,大家可以收藏!!有价值啊!!
Beginning JavaScript with DOM Scripting and Ajax, 2nd Edition: This book will teach you about JavaScript and how to use it in a practical manner. After you read it, you’ll be able to Understand ...
标题 "A tutorial on adding columns to Explorer’s details view via" 是一篇关于如何通过列处理程序外壳扩展在Windows资源管理器(Explorer)的详细视图中添加自定义列的教程。这通常涉及到增强Windows操作系统中...
Adding Ajax – Making Existing Sites More Interactive
<br>What you will learn from this book <br>How to create a better user experience by adding more dynamic UIs Steps for accessing ASP.NET profile and authentication services Ways to ...
The authors utilize ANDROMDA to develop an AJAX cartridge, which automates the generation of a complete AJAX-based web application with integrated backend services. This cartridge streamlines the ...
This is the final part of a three-part ...The purpose of this final article is to complete the introduction to LINQ to SQL by showing how to make your LINQ to SQL classes work with WPF data bindings.
By adding support for XML to Microsoft SQL Server 2000, Microsoft has made it easier than ever to integrate SQL Server–based solutions with existing systems, Web applications, and trading partners....
The first edition was fully revised in 1995, adding new topics such as randomized strategies, finite games with integrated decisions, and refinements of Nash equilibrium. Readers can now look forward ...
While ASP.NET 3.5 boasts server controls like the ListView and the incredibly flexible GridView, it also includes advancements in AJAX technology combined with JavaScript® debugging features in ...
Adding the Map Search Control to your page is a snap. The easiest way is to start with our Map Search Control Wizard. The wizard walks you through some simple customizations and then generates all of ...
JSP(JavaServer Pages)是创建动态 Web 内容的 Java 技术。文档提供了关于如何在 ArcGIS Server 应用中编写和集成 JSP 页面的指南。 10. **编写自定义任务 (9.Writing a Custom Task)** 自定义任务允许开发者...
Finally, we’ll learn how to deploy the application to a virtual server, and install custom domains and SSL certificates. It is my hope that by the time you are finished reading this book, you’ll ...
"Adding Classifications to Web Services"这个过程涉及到将Web服务在SAP NetWeaver Developer Studio中进行分类,以符合SAP的分类系统。 分类(Classifications)的主要目的是让Web服务在服务注册表(Services ...