Java Reference
In-Depth Information
We need to go through this procedure for each text field we wish to autovalidate. In
our example, we need to do it for both required fields in our page (First Name and
Last Name). Once we have set up autovalidation, our fields will be validated via an
Ajax request as soon as they lose focus. If validation fails, the alert component will
display an error message, without doing a full page request.
Notice that the alert's title (summary) and body (detail) messages are exactly the
same. This behavior is not exactly user friendly and can be improved. The solution
is to use the standard JSF error message customization technique. We need to add a
resource bundle (property file) to our application, define some keys that JSF assigns
to standard error messages, and give them custom values to be used as custom
error messages.
When creating Visual JSF projects, a resource bundle is created by default. The file
name is Bundle.properties , and it is located in the default Java package selected
when creating the project. In our project, the file is located in the com.ensode.
visualweb package. We need to add two properties to our resource bundle; one will
set the summary error message to be displayed as the header of the alert, and the
other one will set the detailed error message to be displayed as its body.
We can see the keys for standard JSF error messages by expanding the Libraries
node in the Projects window, then expanding the GlassFish V2 node and jsf-impl.
jar . Inside the javax.faces package we will see a Messages.properties file; this file
contains all standard error message keys (and values).
 
Search WWH ::




Custom Search