Struts2 Validation Using XML

Struts 2 validation using XML example.

package classes;
    package action;

    import com.opensymphony.xwork2.ActionSupport;
    import java.util.Date;
    public class UserAction extends ActionSupport {
        private String userName;
        private String password;
        private String email;
        private Integer age;
        private Date bday;

        public Date getBday() {
            return bday;

        public void setBday(Date bday) {
            this.bday = bday;

        public Integer getAge() {
            return age;

        public void setAge(Integer age) {
            this.age = age;

        public String login() {

            // TODO: login check

            return SUCCESS;

        public String getEmail() {
            return email;

        public void setEmail(String email) {
   = email;
        public String getPassword() {
            return password;

        public void setPassword(String password) {
            this.password = password;

        public String getUserName() {
            return userName;

        public void setUserName(String userName) {
            this.userName = userName;

<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE validators PUBLIC
          "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
    <field name="userName">
        <field-validator type="requiredstring">
            <message>Username Required</message>
    <field name="password">
        <field-validator type="requiredstring">
            <message>Password Required</message>
    <field name="email">
        <field-validator type="email">
            <message>Invalid Email</message>
    <field name="age">
        <field-validator type="required">
            <message>Age Is Required</message>
        <field-validator type="int">
            <param name="min">18</param>
            <param name="max">25</param>
            <message>Invalid Age</message>
    <field name="bday">
        <field-validator type="date">
            <param name="min">12/31/2000</param>
            <param name="max">12/31/2010</param>
            <message>Invalid Date Range</message>


1 comment:

  1. Not see the image name and the price in the shopping cart in its place is the id
    I'm working with struts2 here I show the codes:
    Link is : http://