As a quick fix i changed the validator-rules.xml file. I added the
following:

*if (field == undefined) {*
*   isValid = true;*
} else if { ....
}

I did this for required and mask rules. This solved the problem for me.

Thanks for your response. Moreover with the version of validator framework i
am using i doubt there is *validwhen* available. I need to double check
that.

~madhav



On 4/10/06, Laurie Harper <[EMAIL PROTECTED]> wrote:
>
> Madhav Bhargava wrote:
> > 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?
>
> The validation framework has no way to know the difference between 'the
> control wasn't present on the page' and 'no value was submitted for the
> control' so no, there's no way to tell it to only apply a validation
> when the control is 'there'.
>
> One possibility would be to express your validation constraints with
> validwhen and use a hidden input or something to decide what rules to
> apply.
>
> But a better approach may be to leverage the validation framework's
> 'wizard' support. That allows you to specify a 'page' key on each
> validation rule to control when it's applied. You would need to figure
> out how to map the currently displayed tab to a page key for the
> validator to look at, but that would probably give you a fairly clean
> solution.
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
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