requiredif struts validator to check two fields based on condition
I am trying to validate two fields one is a number and other is an url. At least one of this field has to have a valid value. If the number field has value and it is valid number or i开发者_如何学运维f the url field is present and it is a valid url the validation is passed.
I am using "requiredif" and "mask" to check this. The below is the example of the number checking,
<field property="nombre"
depends="requiredif,mask">
<msg
name="mask"
key="errors.nombre"/>
<arg0 key="nombre"/>
<msg
name="requiredif"
key="errors.validateNombreUrl"/>
<arg0 key="nombre"/>
<var>
<var-name>mask</var-name>
<var-value>${nombre}</var-value>
</var>
<var>
<var-name>url</var-name>
<var-value>((url == null) and (*this* == null))</var-value>
</var>
</field>
In this similar manner, I am checking for the url field as well. But I see the validator validates both the field and shows up error such that BOTH fields are mandatory. How do I make it as a OR condition? I am not sure if the expression in the var value is right for requiredif, because I kind of found it works only for validwhen(which I can't use due to version issues). How do I validated these two fields on a OR condition?
You don't say what Struts version you're using, but requiredif has been deprecated since... a long time. You should be using validwhen, described here. There is an example of what you want.
精彩评论