-
Book Overview & Buying
-
Table Of Contents
Java EE 5 Development with NetBeans 6
Earlier in this chapter we discussed how the required attribute for JSF input fields allows us to easily make input fields mandatory.
If a user attempts to submit a form with one or more required fields missing, an error message is automatically generated.

The error message is generated by the <h:message> tag corresponding to the invalid field. The string First Name in the error message corresponds to the value of the label attribute for the field. Had we omitted the label attribute, the value of the fields id attribute would have been shown instead. As we can see, the required attribute makes it very easy to implement mandatory field functionality in our application.
Recall that the age field is bound to a property of type Integer in our managed bean. If a user enters a value that is not a valid integer into this field, a validation error is automatically generated.

Of course, a negative age wouldn't make much sense, however, our application validates that user input...