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




core JavaServer Faces
Core JavaServer Faces
ISBN: 0131463055
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net