core JavaServer Faces 

 Overview of the Conversion and Validation Process

   

Overview of the Conversion and Validation Process

Let us look at user input in slow motion as it travels from the browser form to the beans that make up the business logic.

First, the user fills in a field of a web form. When the user clicks the submit button, the browser sends the form data to the server. We call this value the request value .

In the "Apply Request Values" phase, the request values are stored in component objects. (Recall that each input tag of the JSF page has a corresponding component object.) The value that is stored in the component object is called the submitted value .

Of course, all request values are strings —after all, the client browser simply sends the strings that the user supplies . On the other hand, the web application deals with arbitrary types, such as int , Date , or even more sophisticated types. A conversion process transforms the incoming strings to those types. In the next section, we discuss conversion in detail.

The converted values are not immediately transmitted to the beans that make up the business logic. Instead, they are first stored inside the component objects as local values . After conversion, the local values are validated . Page designers can specify validation conditions, for example, that certain fields should have a minimum or maximum length. We begin our discussion of validation on page 217. After all local values have been validated, the "Update Model Values" phase starts, and the local values are stored in beans, as specified by their value references.

You may wonder why JSF bothers with local values at all. Couldn't one simply store the request values directly in the model?

JSF uses a two-step approach to make it easier to preserve model integrity. As all programmers know only too well, users will enter wrong information with distressing regularity. Suppose some of the model values had been updated before the first user error was detected . The model might then be in an inconsistent state, and it would be tedious to bring it back to its old state.

For that reason, JSF first converts and validates all user input. If errors are found, the page is simply redisplayed so that the user can try again. The "Update Model Values" phase starts only if all validations are successful.

Figure 6-1 shows the journey of a field value from the browser to the server-side component object and finally to the model bean.

Figure 6-1. A Value Travels from the Browser to the Model

graphics/06fig01.gif


 

Authors: Geary D. Horstmann C.

ISBN: 0131463055   Current page: 53 from 121

This World book online are presented on flylib.com

Our library present to you materials from book core JavaServer Faces.

Warning! The page Overview of the Conversion and Validation Process from this book is informational only! Do not print out this page! Do NOT SUBMIT this page as part of your website or work without confirmation from the authors.

You can read the contents of the book, but we strongly recommend that you purchase. or example, you can Buy this book on Amazon.com


  • Authors:
  • Geary D.
  • Horstmann C.
  • Keys:
  • conversion
  • validation
  • process
  • input
  • travels
  • browser
  • beans
  • business
  • Buy this book on Amazon.com

if you may any questions - contact us: flylib(at)qtcs.net
Privacy Policy