Hi All,

I am using Struts 1.0 and struts-validator 1.0.
I have a JSP which has 3 tabs. Each tab body has a different <input> element
inside it. I am using Ajax to dynamically generate the tab body content.

Let me take an example and explain it. Assume there are 2 tabs - Tab1 and
Tab2.
*Controls in Tab1: *a text field - t1
*Controls in Tab2:* a single select drop down - s1
At any time either the text field is present on the form or a single select
drop down.

In my validation.xml i have validation rules specified for both of these
controls.
*Extract from validation.xml*

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
          "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.0//EN"
          "/WEB-INF/config/dtd/validator_1_0.dtd">

<form-validation>
        <formset>
                <form name="fseSearchForm">
                        <field property="t1" depends="required,minlength">
                                <arg0 key="fsesearchform.t1" />
                                <arg1 key="${var:minlength}" name=
"minlength" resource="false" />
                                <var>
                                        <var-name>minlength</var-name>
                                        <var-value>2</var-value>
                                </var>
                        </field>
                        <field property="s1" depends="mask">
                                <msg key="fsesearchform.mask" name="mask" />
                                <arg0 key="fsesearchform.s1" />
                                <var>
                                        <var-name>mask</var-name>
                                        <var-value>^[0-9]+$</var-value>
                                </var>
                        </field>
                </form>
        </formset>
</form-validation>
When the form is submitted then client side validation occurs using
validation.xml and "An error on page" comes up on the botton left corner of
the web page indicating that there has been an error. The processing does
not stop but the error is displayed.

The problem is that i am unable to create a rule in validation.xml which
will only validate a control if it is present on the generated web page.

*Question:*  Is there any way in which it can be specified that only if the
control is there then validate it else ignore the rule? I guess this problem
must be faced by other people as well.

One option will be: Do client side validations using Javascript functions
and do server side validations using validation.xml/defer till you hit
action and do it explicitely there. But if i have to use struts-validator
framework for client side validations as well then what will the solution?

~Madhav

--
When I tell the truth, it is not for the sake of convincing those who do not
know it, but for the sake of defending those that do

Reply via email to