Book Image

Tapestry 5: Building Web Applications

Book Image

Tapestry 5: Building Web Applications

Overview of this book

Table of Contents (17 chapters)
Tapestry 5
Credits
About the Author
About the Reviewers
Preface
Foreword
Where to Go Next

BeanEditForm Validation


Let's say that when we are adding a new celebrity to our collection the first name should be mandatory. This can be easily achieved by adding a @Validate annotation to either getter or setter method of the Celebrity class, like this:

@Validate("required")
public String getFirstName()
{
return firstName;
}

If you try to add a celebrity without specifying a first name, you will see an appropriate error message, as the Errors component is already incorporated into the BeanEditForm.

You can also specify a custom error message if you do not like the default one. Try something like this:

firstName-required-message=You cannot have a celebrity without a name!

And of course you combine different validators like we did before.