Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add note about required "action" and "namespace"

...

Wiki Markup
{snippet:id=quizValidators|javadoc=false|lang=xml|url=struts2/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/QuizAction-validation.xml}

Action and Namespace

A correct action and namespace attributes must be provided to the <s:form> tag. For example, if the action named "quizClient" is defined in the "/validation" namespace, the form must be configured as:

Code Block
XML
XML

<s:form method="post" validate="true" action="quizClient" namespace="/validation">
   <s:textfield label="Name" name="name"/>
   <s:textfield label="Age" name="age"/>
   <s:textfield label="Favorite color" name="answer"/>
   <s:submit/>
</s:form> 

While the following will "work" in the sense that the form will function correctly, client-side validation will not. That is because Struts must know the exact namespace and action (rather than a URL) to properly support validation.

Code Block
XML
XML

<s:form method="post" validate="true" action="/validation/quizClient.action">
   <s:textfield label="Name" name="name"/>
   <s:textfield label="Age" name="age"/>
   <s:textfield label="Favorite color" name="answer"/>
   <s:submit/>
</s:form>