Form input validation with JAX-RS

Posted by deamon on Stack Overflow See other posts from Stack Overflow or by deamon
Published on 2010-05-14T09:17:57Z Indexed on 2010/05/17 3:40 UTC
Read the original article Hit count: 452

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about jax-rs

Related posts about validation