You can manage conditionals by using expressions and fieldexpressions , so
your validation below would become :
<field name="myInputFieldName">
<field-validator type="fieldexpression">
(#params['myInputFieldName'] neq null) && ( myInputFieldName
neq null & myInputFieldName.trim().length() gt 0 )
<message key="errors.required"/>
</field-validator>
</field>
mleneveut wrote:
>
> Sorry I did'nt understand your answer.
>
> I was talking about some <input/> fileds in my JSP (present in some JPS,
> not in others), and how to write my XML validator file, like :
> <validators>
> <field name="myInputFieldName">
> <field-validator type="requiredstring">
> true
> <message key="errors.required"/>
> </field-validator>
> </field>
> ...
>
>
>
>
>
> cilquirm <[EMAIL PROTECTED]>
> 17/09/2007 16:50
> Veuillez répondre à
> "Struts Users Mailing List" <[email protected]>
>
>
> A
> [email protected]
> cc
>
> Objet
> Re: [S2] Conditional Validation (test if field is present in JSP)
>
>
>
>
>
>
>
> somewhat hackish, but you can accomplish this by using expressions :
>
> #params['attrib'] != null ? attrib in ('a','list','of','values')
>
> (this is just an example stating that you can check for the existence of
> the
> variable in the parameter and then execute an expression like you normally
> would )
>
>
>
> mleneveut wrote:
>>
>> Hi all,
>>
>> We have an Action redirecting to several JSP, depending on the customer.
>
>> But the forms of these JSP are different : some fields are added/removed
>
>> in some JSP.
>>
>> So the automatic validation fails for those fields not existing in some
>> JSP.
>>
>> We bypass the problem by copying the Action method to others Actions
>> (exactly the same code...). We have now one Action for one JSP, so we
>> could have different validation XML file name. But it is not very
> nice...
>>
>> Do we have another solution, like one Action, several JSP, one XML
>> validation file testing if the fields "exist" and if yes doing the field
>
>> validation ? Or setting a flag (hidden field) in the JSPs and doing
>> differents sets of validation depending of this flag ?
>>
>> Thanks for your tips.
>>
>> Regards,
>>
>> Michaël
>>
>
> --
> View this message in context:
> http://www.nabble.com/-S2--Conditional-Validation-%28test-if-field-is-present-in-JSP%29-tf4465421.html#a12737286
>
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
--
View this message in context:
http://www.nabble.com/-S2--Conditional-Validation-%28test-if-field-is-present-in-JSP%29-tf4465421.html#a12738566
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]