ManiKanta G
Wed, 25 Jun 2008 21:14:28 -0700
Hi, Even I've this problem... Here is my requirement....I've 3 fields. On successful validation of 1st field ONLY the 2nd field should be validated, and only with the successful validation of second, then only the 3rd field should be validated against some validation.
I did this by using field validator of type expression, like below...
*<validators>
<field name="returnTo">
<field-validator type="requiredstring" >
<message>Select 'Return to'</message>
</field-validator>
</field>
<field name="sourceId">
<field-validator type="fieldexpression">
<param name="expression">
<![CDATA[((returnTo == null) ||
((sourceId != null) && (sourceId != "--
Select --")))]]></param>
<message>Select company/dealer name</message>
</field-validator>
</field>
<field name="drug">
<field-validator type="fieldexpression">
<param name="expression">
<![CDATA[(((returnTo == null) || ((sourceId == null)
|| (sourceId == "-- Select --"))) ||
((drugsList.size <= 0) || ((drug != null)
&& (drug != "-- Select --"))))]]></param>
<message>Select drug</message>
</field-validator>
</field>
</validators>*
With this, the second case working as it supposed. The second field will
be validated ONLY when the first field is not empty (as in the second
field expression, I m using */returnTo == null/* with short-circuit OR,
and then the actual validation logic of second field).
But the validation logic of the third field (select box) is not working as is supposed to. When I print the expression value using *<s:property value="expression_of_the_third_field_....."/>*, it is printing false, but the validation is being bypassed.
I've tried many ways. But non of 'em worked for me. Is any one got success with this type of validations.
I can implement custom validation using validate(), but I've around 30 transactional forms with this type of requirements.
Am I doing any this wrong? Can anybody please guide me with this... Thanks, ManiKanta Dave Newton wrote:
You either do conditional validations, implement custom validators, or as Lukasz suggested write your own validate() method. When validation is very complex the last may be the best options. Dave --- On Wed, 6/25/08, Istvan Kozma <[EMAIL PROTECTED]> wrote:How the validation should be done for fields which are only displayed in certain conditions? If I do this through the XML file the validation is done all the time even when thefield is not visible.Istvan ----- Original Message ---- From: Dave Newton <[EMAIL PROTECTED]> To: Struts Users Mailing List <user@struts.apache.org> Sent: Wednesday, June 25, 2008 3:37:38 PM Subject: Re: validation problem Whoops, as the other reply said, it's the <s:fielderror...> tag [1], not <s:actionerror>. Dave [1] http://struts.apache.org/2.x/docs/fielderror.html --- On Wed, 6/25/08, Dave Newton <[EMAIL PROTECTED]> wrote:--- On Wed, 6/25/08, Anshu Dhamija wrote:i am facing problem in performing validationthroughofxml actually i want to display message at the topmy form instaed of at field level can anyone please help meThe validation messages are placed in the form by theS2form element tags. If you want to modify the output of those tags you can modify or create a theme [1]. Using the "simple" theme will also removethevalidation messages, but you'll lose other useful functionality--but that might not be an issuedepending onyour usecase. The <s:actionerror...> tag [2] will render anyerrormessages. A combination of either the simple theme oramodified theme plus the action error tag may do whatyouneed. Dave [1]http://struts.apache.org/2.x/docs/themes-and-templates.html[2] http://struts.apache.org/2.x/docs/actionerror.html--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
********** DISCLAIMER **********Information contained and transmitted by this E-MAIL is proprietary to Sify Limited and is intended for use only by the individual or entity to which it is addressed, and may contain information that is privileged, confidential or exempt from disclosure under applicable law. If this is a forwarded message, the content of this E-MAIL may not have been sent with the authority of the Company. If you are not the intended recipient, an agent of the intended recipient or a person responsible for delivering the information to the named recipient, you are notified that any use, distribution, transmission, printing, copying or dissemination of this information in any way or in any manner is strictly prohibited. If you have received this communication in error, please delete this mail & notify us immediately at [EMAIL PROTECTED]