Take the 2-minute tour ×

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 if 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"
                    <arg0 key="nombre"/>

                    <arg0 key="nombre"/>


                <var-value>((url == null) and (*this* == null))</var-value>

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
thanks for the pointer. Now I am using something like this <var> <var-name>test</var-name> <var-value>((url == null) and (this != null))</var-value> </var> But this is throwing error when the url is null and the nombre field is a valid number :( Is there something wrong with the conditions? –  Abhishek Sep 9 '11 at 4:54
I don't know; can't see the rest of the validation config. –  Dave Newton Sep 9 '11 at 12:16

Your Answer


