FacesMessages Basics

In your XHTML Page:


	
	Name: 
	

In your backing bean:

// to show up where globalOnly messages appear
facesMessages.add("Changes were not applied...");

// do your field-level validation
facesMessages.addToControl("name", "Name was not valid.");

Results:
Picture 2.png

Update your CSS to fit your style preferences.

Hibernate Validation

Here’s a list of annotations that you can use to validate java beans:

  • @Length(min=, max=) Checks whether the string length matches the range
  • @Max(value=) Checks that the value is less than or equal to the max
  • @Min(value=) Checks that the value is greater than or equal to the min
  • @NotNull Checks that the value is not null
  • @Past For a date object, checks that the date is in the past
  • @Future For a date object, checks that the date is in the future
  • @Pattern(regex=”regexp”, flag=) For a string, checks that the string matches this pattern
  • @Range(min=, max=) Checks whether the value is between the min and the max
  • @Size(min=, max=) For collections, checks that the size is between the two
  • @AssertFalse Asserts that the evaluation of the method is false
  • @AssertTrue Asserts that the evaluation of the method is true
  • @Valid For a collection or a map, checks that all the objects they contain are valid
  • @Email Checks whether the string conforms to the email address specification

From Depressed Programmer.

Onyxbits

I found an interesting set of Java tools at OnyxBits. Included is an animated gif maker, LDAP utilities, a program for drawing comics, and more.