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.