O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Validating Input

There are two types of input validation you must consider in any application: syntactic and semantic validation. A form field value that represents a date, for instance, must be written in a certain format (i.e., be syntactically correct) in order to be interpreted by the application. It may also have to follow other rules (i.e., be semantically correct) to be accepted, e.g., be a date in the future or later than another date.

In JSF, components perform syntactic validation typically during the conversion from a request parameter string value to the native type of the business data property bound to the component. For semantic validation, you can attach validators to the components. JSF comes with a set of standard validators for the most common validation needs and lets you develop custom validators for more complex rules. We'll look at both alternatives in this chapter.

Dealing with Syntax Errors in User Input

In Chapter 6, we created a few components, arranged them as a component tree in a view, rendered them to the browser, and saved the view state either in the response itself or on the server. Presumably, there's a user sitting there admiring our nice form with an input field and a button. Let's see what happens when she submits the form.

First, JSF must figure out which view to use for processing the request. This information is encoded in the URI itself. As you may recall from Chapter 6, we've decided to use the default extension mapping for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required