Hi,

I'm new to Struts 2 and am still trying to figure out some of the basics.

The first problem I'm having, is with an action that uses ModelDriven. The model that I'm using has 2 fields that are both required, one is a string and one is an int. I'm stuck on two things. The first is that when validation fails, no error messages are being displayed. I was under the impression that the <s:textfield> tag should be able to determine when the model has an error on its matching field (via the value stack) and display and error message. If I uses attributes in my Action instead of ModelDriven, then the textfield tag display error messages correctly.

The next problem, is that if I don't enter a value for the Age field (int), when the form is redisplayed the Age field has been populated with 0. If the Age field is left empty, I'd like the field to stay empty when the form is redisplayed.

The model, action and view I'm using are below. Any help is greatly appreciated.

Thanks,
Steven



@Validation
public class User {

   private int age;
private String name; @RequiredFieldValidator(message="Age is required.")
   public int getAge() {
       return age;
   }

   public void setAge(int _age) {
       this.age = _age
   }
@RequiredFieldValidator(message="Name is required.")
   public int getName() {
       return this.name;
   }
public void setName(int _name) {
       this.name = _name;
} }


Action:

@Validation
public class CreateUserAction extends ActionSupport implements ModelDriven<User> { private User user = new User(); @VisitorFieldValidator(message="")
   public User getModel() {
       return this.user;
   }

   public String execute() {
       return "input";
   }

}


View:

 <h2>New User</h2>
 <s:form action="create">
<s:textfield name="age" label="Age" required="true"/> <s:textfield name="name" label="Name" required="true"/> <s:submit/> </s:form>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to