I just tried to implement clientside validation like that and ran into the 
problem that I get "Incompatible return types" for @OneToMany etc. 
associations as one has to use the Proxy types as return types in the Proxy 
interfaces and the Entity interfaces in the Entity interfaces. Anyone has 
an idea how it could be possible to get around that? :) 

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.
>
>
> @Entity
> public class Employee extends EntityBase implements EmployeeProxy {
>       @Column(nullable = false) 
>       private String firstName;
>       @Override
> public String getFirstName() {
> return firstName;
> }
>        /* ......................   */
>        @Override
> public 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>() {
>  @Override
> public void onSuccess(Void response) {
> Window.alert("Succeed");
> }
>  @Override
> public 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to