This will look for a resource bundle called messages and inside it for the login.username.length property to retrieve the message.You could alternately just write the message in plain old English inside the annotation but why would you want to when you can internationalize.
The last thing we need to do is tell the JSF page that it will need validation (I think this is a somewhat redundant step since the bean is already annotated but nonetheless it is required).You must wrap the fields of the login form around the Note: Be sure to specify required=”true” for the fields you want to apply annotation validations to.I would recommend overriding onfocusout if you want to modify this [email protected] thoughts on the current behavior of onfocusout, and other "required" checks before submit, in general?This article lists some routine tasks for JSF developers and gives tips and tricks on how to pass values efficiently without having to pollute the session-object.
The intended audience for this article are novice JSF developers as well as developers that are interested in alternative solutions to common problems.
By default validation messages are displayed in a format that is not very intuitive, in order to change the format you must override a property in your tag.
So in the above case if login.username is defined to be “Username” in the resource bundle, the messages that will be printed will be: Username is a required field. This is probably the most powerful way of validating user input – programmatically.
Problems caused by wrong Bean Scopes are often hard to trace and require profound knowledge of the JSF framework (and the fundamental principles of web applications in general).
This is why particularly developers new to JSF get easily in trouble by excessively using Session Scoped Beans.
Otherwise, you’ll see some very weird results such as only non-blank fields getting the annotation validations applied to while the blank fields get considered valid.