Conditional Validation

I am using the Struts validation.xml to check if clients leave any of the required text fields in the form blank.

I prepared two action mappings for this web page. The 'validate'attribute is set to "false" for the first action mapping because when I have the web page displayed in the browserat the first time, I do not want to perform the validation check.

The 'validate' attribute is set to "true" for the second action mapping so that validation is performed if clients click on the "Submit" button.

So far so good.

But, there is also a "Close" button in the web page. If the 'Close' button is clicked, the previous web page is supposed to be displayed.

Clients are not expected to fill out the form should they choose to click on the 'Close' button. What should I do if I do not want to perform the validation check if the 'Close' button is clicked?

[900 byte] By [jiapei_jena] at [2007-10-3 1:38:59]
# 1

Sounds like you want a "cancel" type button.

You can use <html:cancel value="Close"/> to render a standard html cancel button.

Basically struts looks for the presence of the parameter "org.apache.struts.taglib.html.CANCEL"

If it is present, then the action is treated as a cancel action, and validation is skipped.

evnafetsa at 2007-7-14 18:37:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for trying to help me again.

<html:cancel value="Close"/> does not work (leads to runtime error: the page cannot be fourn) in the application on which I am working.

I am coding this way (no runtime error but cannot stop validating):

<html:submit property="method">

<bean:message bundle="default" key="coommon.button.close" />

</html:submit>

jiapei_jena at 2007-7-14 18:37:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...