Am Samstag, 13. Oktober 2012 05:29:10 UTC+2 schrieb Daniel Mauricio Patino León:
Hello there.--I have a question of wich is the best option to validate my domain objects on the client side with RequestFactory.It's posible to validate a Proxy with the new Validation of 2.5 RC2 ?If i do a validation of my proxy don't get any constraints violations.What i did to get a work arround of this was move the anoations to my proxy:@ProxyFor(value=Employee.class, locator=EntityLocator.class) public interface EmployeeProxy extends EntityProxy {@NotNull(message="Cannot be empty.")@Size(min = 4, message = "Name must be at least 4 characters long.")public String getFirstName();/* ...................... */}Then i implemented that interface on my domain object.@Entitypublic class Employee extends EntityBase implements EmployeeProxy {@Column(nullable = false)private String firstName;@Overridepublic String getFirstName() {return firstName;}/* ...................... */@Overridepublic EntityProxyId<?> stableId() {return null;}}Now i get validation on the client side with:EmployeeRequest request = requestFactory.employeeRequest(); EmployeeProxy employeeProxy = request.create(EmployeeProxy.class); request.addNewEmployee(employeeProxy); driver.edit(employeeProxy, request);Set<ConstraintViolation<EmployeeProxy>> violations = validator.validate( employeeProxy); System.out.println(violations); and also on the server side when i click on save button with this:driver.flush().fire(new Receiver<Void>() {@Overridepublic void onSuccess(Void response) {Window.alert("Succeed");}@Overridepublic void onConstraintViolation(Set<ConstraintViolation<?>> violations) { //ConstraintViolation<?> violation = violations.iterator().next();//Window.alert(violation.getMessage() + " " +violation.getPropertyPath(). toString()); for(ConstraintViolation<?> violation: violations){if(violation.getPropertyPath().toString().equals("age")){ ageError.setText(violation.getMessage()); }else if(violation.getPropertyPath().toString().equals("firstName" )){ firstNameError.setText(violation.getMessage()); }else if(violation.getPropertyPath().toString().equals("lastName") ){ lastNameError.setText(violation.getMessage()); }}// ... others}});I this correct?This can cause problems ?thank you.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/rqL48dqNCtIJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment