top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

VisitorFieldValidation with annotations at action level in Javabean

+1 vote
146 views

I have an action with a getter/setter of a bean :

public class MyAction extends ActionSupport implements Preparable {
 private BeanEvent event = null;
 public void prepare() {
 this.event = new BeanEvent();
 }
 public BeanEvent getEvent() {
 return this.event;
 }
 public void setEvent(BeanEvent e) {
 this.event = e;
 }
}

The bean is a standard Java bean with getters and setters for some properties. I would like to validate the bean using annotations at MyAction level, so no annotations would be needed in the BeanEvent. I understand that the VisitorFieldValidation allows to use validation for beans, but only when definining the actual validation in the bean. Is there any way I could define the validation at the Action level?

posted May 28, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

We have a websocket application which keeps writing data to the clients.

We found that when tabs (not whole browser) of Firefox (ver. 22) is closed, the websocket connection is not closed. Anyway, reproducibility is very low. And the sendQ (netstat -an) keeps growing

So, what we did is. we kept sending heart beat from client. If this heart beat timeout occurs, we are trying to close the connection as follows

ByteBuffer bbuff = ByteBuffer.allocate(1);
bbuff.put((byte) 0);
messageInbound.getWsOutbound().close(0, bbuff);

Is this correct approach to close the connection from server? Because, the connection is not closed at lower level (netstat -an). Anyway, writing data to it , is stopped and sendQ stops growing.

# netstat -an | grep :8080
tcp 0 402376 172.22.59.176:8080 198.162.18.207:64805 ESTABLISHED
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

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

+1 vote

Sometimes it happens that with firefox after each page change during creation of a new bug new login is required. So the page with login information is shown (not the login at the header line)

With IE or Chrome at the same time this does not happen. Does anyone know how the firefox can used without the repeating login?

...