Hi ManiKanta,

Thanks for the reply. Checkbox always has a value of true/false.

Below is the validation entry which is working for me - 

<field name="fieldname">
        <field-validator type="fieldexpression">
            <param name="expression">
            <![CDATA[((checkbox != true) && (fieldname != ""))]]></param>
            <message>Error Message.</message>
        </field-validator>
 </field>

Regards,
Richa

-----Original Message-----
From: ManiKanta G [mailto:go4m...@gmail.com] 
Sent: Thursday, December 11, 2008 10:28 PM
To: Struts Users Mailing List
Subject: Re: Struts 2 - Conditional Validation

>
>      <field-validator type="conditionalvisitor">

            (checkbox == true) and (textbox).equals("")
>


Unless u wrote ur custom validator dealig the 'checkbox == true' comparison,
by default these type of comparisons will not work.

You have to specify the check box's value (check box based which you want to
perform conditional validation) rather 'true' (coz when the server receives
request the form values will hold the name-value pairs, but not the
checked/unchecked or true/false details).

So the correct logic would be turned into something like,

        <field-validator type="fieldexpression">
            <param name="expression">
            <![CDATA[((check_box != "cbVal") || (depending_field !=
"fieldVal"))]]></param>
            <message>Some error message</message>
        </field-validator>

If u use the above 'fieldexpression' validator, if the first condition is
evaluated to true i.e, if the check box is not checked, then the second
expression will not be evaluated.

Comparision may be altered using && also with first expression's comparision
reversed.

Hope this helps.

ManiKanta


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to