Hi,
I am getting an exception when using validation framework with html:optionsCollection
stuts-config
<action path="/initProfile"
name="documentProfile"
parameter="populate"
validate="false"
scope="request"
input="/pages/createprofile.jsp"
validate="true"
type="com.krishct.efiler.user.actions.DocumentProfileAction">
<forward name="success" path="/pages/createprofile.jsp"/>
</action>
<form-bean name="documentProfile" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="branches" type="java.util.List"/>
<form-property name="departments" type="java.util.List"/>
</form-bean>
validation.xml
<form name="documentProfile">
<field property="branchId" depends="required">
<msg name="required" bundle="user" key="errors.required" />
<arg bundle="user" key="user.branch" />
</field>
<field property="departmentId" depends="required">
<msg name="required" bundle="user" key="errors.required" />
<arg bundle="user" key="user.department" />
</field>
</form>
JSP
<html:form action="/documentProfileAction.do">
<table width="90%" >
<tr>
<td><bean:message bundle="user" key="user.branch" />
<FONT face=Arial color=#cc0000 size=2><B>*</B></FONT></td>
<td><html:select property="branchId" onchange="getDeptByBranch();" style="textbox" name="documentProfile" styleId="branchId" >
<html:option value="">Select Branch</html:option> <html:optionsCollection property="branches" name="documentProfile" value="branchId" label="branchName" />
</html:select>
</td>
<td><font color="red"><html:errors bundle="user" property="branchId" ></html:errors></font></td>
</tr>
<tr>
<td><bean:message bundle="user" key="user.department"/>
<FONT face=Arial color=#cc0000 size=2><B>*</B></FONT></td>
<td>
<html:select property="departmentId" onchange="getDocumentsByDept();" styleId="departmentId" name="documentProfile">
<html:option value="">Select Department</html:option> <html:optionsCollection property="departments" value="departmentId" label="departmentName"/>
</html:select>
</td>
<td><font color="red"><html:errors bundle="user" property="departmentId" ></html:errors></font></td>
</tr>
<tr><td><html:submit/></td></tr>
</table>
</html:form>
Action class
public ActionForward populate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm dform=(DynaValidatorForm)form;
List branches=iUserLocation.getBranch();
List departments=iUserLocation.getDepartments();
dform.set("branches", branches);
dform.set("departments", departments);
return mapping.findForward("success");
}
When ever I click on submit button with out selecting the value in select box. Instead of validating its raising exception
javax.servlet.jsp.JspException: Failed to obtain specified collection
How to avoid this. Guide me.
Thanking you.
--raaja. g