top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Validator with annotations

0 votes

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

private String email;

@RequiredStringValidator(key="fieldError.required", message = "*")
 @EmailValidator (key="fieldError.emailFormat", message="*")
public void setEmail(String 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) {

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

posted Jun 28, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

have a look at VisitorFieldValidator [1] [2] and model driven. IMO it's better to keep the annotations inside the action rather than the bean (you can have different use cases for the same model).


answer Jun 28, 2013 by anonymous
Similar Questions
+1 vote

I am using s:select to create a dropdown and then checked the html. I wanted to add bgcolor as yellow. I referred to the following link

but still not sure how to put the background clour as yellow. Can anyone provide any pointers? Also, is it OK to use JSTL tags in JSPs in a Struts 2 application ?

0 votes

Have anybody tried with using jersey along with struts for the rest api.

Before I have an execute() method in the rest api that has code for redirecting into get , and now if I replace my code with jersey path annotations how can I use the work done by action in struts

+1 vote

Facing some issue, while we use wildfly-deploy maven plugin to deploy strut2 application to wildfly aka jboss 7, struts2 is unable to read file packaged inside .war. If i deploy from an IDE or manually then there is no issue.

The only difference is wildfly-deploy plugin is deploying application war inside {WILDFLY_HOME}/standalone/data/ folder where as manual or IDE will deploy it under {WILDFLY_HOME}/standalone/deployments/ folder.

In essence struts2 unable to read file if deployed under certain location.

Any thoughts, application is working perfectly except label's are not coming only label key is coming in screens.

+1 vote

Will it restrict the information being stored at the browser cache.

+3 votes

I would like to integrate struts2 in an CRUD application , JDBC, Apache Tomcat, Netbeans (or eclipse) but without Hibernate , nor EJB, nor GlassFish.
Hibernate is more complex than the problem it tries to solve. Could you have any integration example please ?