Hi, I have some doubt about how to use validation annotation.
I'm changing my code to make it more readable and maintainable.

I started from an action where I had all setters with annotation and i put
data in a private local variable

ex.
private String email;

@RequiredStringValidator(key="fieldError.required", message = "*")
 @EmailValidator (key="fieldError.emailFormat", message="*")
public void setEmail(String email) {
 this.email = email;
}

It functioned well but I neeed to reorganize my code.
So, I create e class User where I directly put data coming from the web and
I erase all the private variable in this way

User user = null;
 public User getUser() {
if (user == null)
user = new User();
 return user;
}

@RequiredStringValidator(key="fieldError.required", message = "*")
 @EmailValidator (key="fieldError.emailFormat", message="*")
public void setEmail(String email) {
 getUser().setEmail(email);
}

My bean receives data but validators stop to function, so I receive bad
validation messages
Does validator need a getter (not present also in the first release) or use
reflection on local variables to check data?
How can I implement my new data model in Struts2

<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2-core</artifactId>
  <version>2.3.14</version>
</dependency>


Kind regards
Simone Buzzi

Reply via email to