You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Raghu Kanchustambham <kr...@gmail.com> on 2005/11/20 11:28:31 UTC

Validator framework with indexed properties

Hi,
I was hoping that the following should work ... but I guess I am missing
something somewhere.. validation with other properties is working fine.. but
not with the indexed properties.
  Struts-config.xml:
 <form-bean name="studentEnquiryForm" type="
org.apache.struts.validator.DynaValidatorForm">
<form-property name="studentEnquiry" type="
com.tuningfork.student.businessobject.enquiry.StudentEnquiry"/>
<form-property name="contactAddress" type="
com.tuningfork.student.businessobject.enquiry.StudentAddress"/>
<form-property name="permanentAddress" type="
com.tuningfork.student.businessobject.enquiry.StudentAddress"/>
<form-property name="educationDetails" type="
com.tuningfork.student.businessobject.enquiry.StudentEducationDetail[]"
size="4"/>
<form-property name="workExperience" type="
com.tuningfork.student.businessobject.enquiry.StudentWorkExperience"/>
<form-property name="enquiryCentreId" type="java.lang.Integer"/>
<form-property name="enquiryCourseId" type="java.lang.Integer"/>
<form-property name="studentEnquiryId" type="java.lang.Integer"/>
<form-property name="newsPaperIds" type="int[]"/>
<form-property name="discoverySourceIds" type="int[]"/>
<form-property name="centreTimePreferences" type="
com.tuningfork.student.businessobject.enquiry.StudentCentreTimePreference[]"
size="2"/>
</form-bean>

<action attribute="studentEnquiryForm" name="studentEnquiryForm"
path="/StudentEnquiryPre" scope="request"
validate="false" type="com.tuningfork.student.action.StudentEnquiryAction"
parameter="operation" roles="Administrator,Counsellor">
<forward name="preCreateSuccess" path="/student/StudentEnquiry.jsp"/>
<forward name="preUpdateSuccess" path="/student/StudentEnquiry.jsp"/>
<forward name="viewSuccess" path="/student/StudentEnquiry.jsp"/>
</action>

<action attribute="studentEnquiryForm" name="studentEnquiryForm"
path="/StudentEnquiry" scope="request"
validate="true" type="com.tuningfork.student.action.StudentEnquiryAction"
parameter="operation" input="/StudentEnquiryPre.do?operation=validateFailed"
roles="Administrator,Counsellor">
<forward name="preCreateSuccess" path="/student/StudentEnquiry.jsp"/>
<forward name="viewSuccess" path="/student/StudentEnquiry.jsp"/>
<forward name="createSuccess" path="/home.jsp"/>
<forward name="updateSuccess" path="/home.jsp"/>
<forward name="createAndEnrollSuccess"
path="/StudentEnrollment.do?operation=preCreate&amp;postTo=
StudentEnrollment.do"/>
</action>

 validation.xml: I am trying to validate the indexed property of the
completionDate of educationDetails. I have all the following entries in my
validation.xml in the hope that atleast one of it will work... but none
seems to...

 <field property="educationDetails[0].completionDate"
depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails[1].completionDate"
depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails.completionDate[0]"
depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails.completionDate[1]"
depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails[].completionDate" depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails.completionDate[]" depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>
<field property="educationDetails.completionDate" depends="required,date">
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yy</var-value>
</var>
</field>

 Note that I am successfully able to validate other fields on this form like
studentEnquiry.firstName etc.... it is not validating only the indexed
properties.

If it matters... I am using struts 1.1.

 Please let me know what I am doing wrong.

Thanks much.

Regards,

Raghu