[ 
https://issues.apache.org/struts/browse/WW-2113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41901
 ] 

J Alex commented on WW-2113:
----------------------------

Please evaluate and assign a suitable priority. I had left it as "Minor" since 
i didn't know if i was asking for something which was already 
present/implementable with current framework.

> Conditional check before firing further validations (shortCircuit without 
> error)
> --------------------------------------------------------------------------------
>
>                 Key: WW-2113
>                 URL: https://issues.apache.org/struts/browse/WW-2113
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Interceptors
>    Affects Versions: 2.0.9
>         Environment: N/A
>            Reporter: J Alex
>            Priority: Minor
>             Fix For: Future
>
>
> Hi,
> Consider the following scenario : 
> Field A needs to be validated only if certain conditions on fields B , C etc. 
> are satisfied ; ex : we need to validate "previous address" fields only if 
> "time at current address" = 2 ; otherwise, we dont care abt the values 
> entered in these fields.
> In Struts 1.x, the way i did this was to define a custom validator 
> (prevAddrTest) that would only return true if  "time at current address" = 2 
> ; false otherwise - without adding any error messages.
> In validation xml ; prefix this validator before the actual validators for 
> this field
> ie . <field property="previousAddress.addressLine1" 
> depends="prevAddrTest,mask,minlength"> 
> So, if prevAddrTest returned false, the remaining validators will not fire 
> (i.e they are shortCircuited)
> Now, in Struts 2.x, we must have an error message for the shortCircuit to 
> happen, and that would cause pageflow to stop at input, while our actual 
> intention is to continue to next page, since the dependent fields can be 
> ignored.
> As it stands, i've managed to workaround this by tweaking the workflow 
> interceptor to look for a particular error message that'll be thrown by such 
> "check" validators, and continue to next page - and in the <s:fielderror> 
> tag, add a condition to suppress these messages. I think this is not the 
> right way to do it.
> Please let me know if i'm missing anything that the framework provides for 
> this - if not, i think the following will be a good enhancement.
> Suggested validator name : expressionCheck 
> Function : evaluate the expression and if false ; shortcircuit the remaining 
> validators on the fields - **without adding any error message** . 
> Benefit : Implement dependent validations on fields
> I've also posted this on Nabble as a response to Matt Raibile's conditional 
> validator implementation :
> http://www.nabble.com/Conditional-validation-tf3678771.html#a12137461
> Thanks,
> Joseph

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to