Form input validation with JAX-RS
- by deamon
I want to use JAX-RS REST services as a back-end for a web application used directly by humans with browsers. Since humans make mistakes from time to time I want to validate the form input and redisplay the form with validation message, if something wrong was entered. By default JAX-RS sends a 400 or 404 status code if not all or wrong values were send.
Say for example the user entered a "xyz" in the form field "count":
@POST
public void create(@FormParam("count") int count) {
...
}
JAX-RS could not convert "xyz" to int and returns "400 Bad Request".
How can I tell the user that he entered an illegal value into the field "count"? Is there something more convenient than using Strings everywhere and perform conversation by hand?