Hi All,
 
I am adding some new validation to a form that is currently being
managed by the validation framework. My form has several properties that
are now optional. The user is to supply a URL and a corresponding label.
The user has the option to enter 1-6 Label/URL combinations. I need to
require a label/URL entry only if a value has been added for one of the
pair. I have read in the documentation that there is new support for
conditionaly required fields but I am having difficulty understanding
how it works and how to implement. The example shown here
<http://jakarta.apache.org/struts/userGuide/dev_validator.html>  shows a
form defined in struts-config.xml containting a property of type
org.apache.struts.webapp.validator.Dependent[] and a entry in the
validation.xml that uses some conditional evaluations on a form field as
shown below.
 
If you have this in your struts-config.xml 
<form-bean
    name="dependentlistForm"
    type="org.apache.struts.webapp.validator.forms.ValidatorForm">
    <form-property
        name="dependents"
        type="org.apache.struts.webapp.validator.Dependent[]"
        initial="{'','','','','','','','','','',''}"/>
    <form-property
        name="insureDependents"
        type="java.lang.Boolean"
        initial="false"/>
</form-bean>
 
You can define a validation: 
 
<form name="dependentlistForm">
 
<field
    property="firstName" indexedListProperty="dependents"
    depends="requiredif">
  <arg0 key="dependentlistForm.firstName.label"/>
  <var>
    <var-name>field[0]</var-name>
    <var-value>lastName</var-value>
  </var>
  <var>
    <var-name>field-indexed[0]</var-name>
    <var-value>true</var-value>
  </var>
  <var>
    <var-name>field-test[0]</var-name>
    <var-value>NOTNULL</var-value>
  </var>
</field>
 
Could anyone help explain how to use the
org.apache.struts.webapp.validator.Dependent[] and the
"indexedListProperty" to provide the functionality I require?
 
Many thanks,
 
Greg
 

Reply via email to