Subject: Re: Struts Validation - Stop on fail?
From: "Andrej Sobkowski" <[EMAIL PROTECTED]>
 ===
Hello,

Padma Ginnaram replied to me directly (thanks!) so here is the message in
case someone was having a similar problem:
--- From Padma's message
[...]
If a validator depends on other validators, it is not invoked unless all the
dependencies are successful. Your float validator might be dependent on
required which could cause the behavior you are seeing. You can remove this
dependency if you don't want this behavior.

This functionality is useful if you donot want to run a validator like
'daterange' unless date validator is successful.
[...]
--- End

FYI, the "depends" information is in the validator-rules.xml file ('depends'
validator attribute). If you want to change this behaviour so that the
validations are called even if the dependent fails, remove the attribute.
This implies that you must add "required" as a field validation (in
validation.xml) to make sure that you don't try to validate as a float an
empty String (which would fail).

HTH. Thanks again to Padma for his reply.

Andrej


"Andrej Sobkowski" <[EMAIL PROTECTED]> wrote in message
news:ag1l48$ekh$[EMAIL PROTECTED]...
> Hello,
>
> I've been using the Struts Validator on a couple of projects with no pbs
but
> I'm now stuck with a (probably easy-to-solve) issue. I have a super-basic
> bean with 3 properties: name, density, concentration. Both density and
> concentration are required and must be float. My validation.xml is shown
> below... standard, easy, nothing special.
>
> The problem is that if I enter an invalid concentration (not a float) and
I
> leave density empty, I only get one message saying: "Density is required"
> (no mention about the invalid concentration). If I then enter invalid
> concentration and density, I get the proper results ("Density must be a
> float. Concentration must be a float"). It looks like the "required" gets
> the priority on the other validations. Is this normal?
>
> Does anybody have any ideas about what I'm doing wrong? I'm pretty sure
it's
> something minor...
>
> Thanks.
>
> Andrej
>
>
> I'm working with Struts 1.1b1 with Tomcat 4.0.4 under Win2k.
>
> <!-- bottom of struts-config.xml -->
>   <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
>     <set-property property="pathname"
value="/WEB-INF/validator-rules.xml"/>
>     <set-property property="pathname"
> value="/WEB-INF/slb-validator-rules.xml"/>
>     <set-property property="pathname" value="/WEB-INF/validation.xml"/>
>   </plug-in>
>
> <!-- validation.xml -->
> <form-validation>
>   <formset>
>     <form    name="baseFluidForm">
>       <field property="name"
>              depends="required">
>         <arg0 key="name"/>
>       </field>
>       <field property="density"
>              depends="required,float">
>         <arg0 key="density"/>
>       </field>
>       <field property="concentration"
>              depends="required,float">
>         <arg0 key="concentration"/>
>       </field>
>     </form>
>     </form>
>   </formset>
> </form-validation>
>
>
>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to