Class MandatoryIfOtherFieldEmpty

java.lang.Object
com.apgar.common.lib.constraint.BundledConstraint
com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty
All Implemented Interfaces:
Constraint<Object>, ConstraintOnNull, JavaBeanVersion

public class MandatoryIfOtherFieldEmpty extends BundledConstraint implements Constraint<Object>, ConstraintOnNull
Constraint that checks if one field is filled, the other field should be empty. Both fields cannot be empty.

The error message and/or information message created in the error.properties and text.properties files respectively will be displayed if the constraint is not verified.

  • error.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty You must either enter field '{0}' or '{1}' but not both
  • text.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty You must either enter field '{0}' or '{1}' but not both
  • error.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty.nullCase Field '{0}' and '{1}' cannot both be empty
  • text.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty.nullCase Field '{0}' and '{1}' cannot both be empty

This constraint is defined in the XSD under the field and takes for argument the path of the second field to be compared to.

 <xs:element name="sampleField" minOccurs="0" maxOccurs="1">
     <xs:annotation>
         <xs:documentation xml:lang="en-US">
             <osd:label>Sample Field</osd:label>
         </xs:documentation>
         <xs:appinfo>
             <osd:otherFacets>
             <osd:constraint class="com.apgar.common.lib.constraint.MandatoryIfOtherFieldEmpty">
                 <otherFieldPath>../otherField</otherFieldPath>
                 <bothNullEndKeysProperty>nullCase</bothNullEndKeysProperty>
             </osd:constraint>
             </osd:otherFacets>
         </xs:appinfo>
     </xs:annotation>
 </xs:element>
 
Author:
APGAR Consulting
  • Constructor Details

    • MandatoryIfOtherFieldEmpty

      public MandatoryIfOtherFieldEmpty()
  • Method Details