Hi Guillaume
Generally speaking, in GWT you would like to have the constraint violations
thrown the Editor framework on the client side. But there are of course some
constraint violations that can only be checked server-side, e.g. unique
violations that need a query to check the validity.
For these cases, I do exactly what you are suggesting. My server-side classes
throw a custom ConstraintViolationException which I intercept in my
StatusService. When the StatusService sees a ConstraintViolationException, I
return a Status.CLIENT_ERROR_BAD_REQUEST to the client and I serialize the
actual violation in the payload. Here's a snippet of my StatusService :
if (cause instanceof ConstraintViolationsException) {
ConstraintViolationsException e = (ConstraintViolationsException) cause;
String msg = "";
for (ConstraintViolation<DomainResource> violation : e.getViolations()) {
msg += violation.getMessageTemplate();
msg += ";";
}
getContext().getAttributes().put(STRING_REPRESENTATION, msg);
ret = new Status(Status.CLIENT_ERROR_BAD_REQUEST, cause, msg);
} + "> at resource <" +
resource.getReference() + ">");
In my GWT client, the onFailure checks the response code and when it sees
CLIENT_ERROR_BAD_REQUEST, it deserializes the payload into constraint
violations and emits them on the event bus. Any interested widget can then
respond by displaying the error.
Hope this helps.
Koen
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071375