0

For the Struts 1 validation XML file, is it possible to say that field x OR field y is required?

Here is the syntax that I have in the xml file:

<form name="/save">
    <field property="email" depends="required">
            <arg0 key="Email" resource="false"/>
        </field>
    <field property="phone" depends="required">
        <arg0 key="Phone" resource="false"/>
    </field>
</form>

The above snippet requires BOTH email and phone to be filled out. I want to require either email OR phone.

Is this possible in Struts 1 validator? I know that I can do this in java code, but I'm curious if it can be done in the struts 1 validation.xml file.

Thanks

David
  • 1,013
  • 3
  • 13
  • 18

1 Answers1

0

As a workaround, I added a validate method to my ActionForm with my custom logic based on instructions from this post on stackoverflow.

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
  ActionErrors errors = new ActionErrors();
  if ((phone==null) && (email == null)) 
      errors.add("email", new ActionError("error.phoneOrEmail"));
  return errors;
}
Community
  • 1
  • 1
David
  • 1,013
  • 3
  • 13
  • 18