Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Validation > Basic Validation
Added by tm_jee, last edited by Ted Husted on Sep 04, 2006  (view change)

Let's configure a basic validation workflow, step by step.

Step 1

Create the input form.

<html>
<head>
    <title>Validation - Basic</title>
    <s:head/>
</head>

<body>

<b>What is your favorite color?</b>
<p/>

<s:form method="post">
    <s:textfield label="Name" name="name"/>
    <s:textfield label="Age" name="age"/>
    <s:textfield label="Favorite color" name="answer"/>
    <s:submit/>
</s:form>

</body>
</html>

Step 2

Create the Action class.

public class QuizAction extends ActionSupport {

    private static final long serialVersionUID = -7505437345373234225L;

    String name;
    int age;
    String answer;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }
}

Step 3

Create the validators. The validation.xml format is either <ActionClassName>validation.xml or <ActionClassName><ActionAliasName>-validation.xml.

An error occurred: http://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction-validation.xml. The system administrator has been notified.