aspose file tools*
The moose likes Struts and the fly likes problem with html:optionsCollection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem with html:optionsCollection" Watch "problem with html:optionsCollection" New topic
Author

problem with html:optionsCollection

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 112
Hi,

I am getting an exception when using validation framework with htmlptionsCollection

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" >
<htmlption value="">Select Branch</htmlption> <htmlptionsCollection 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">
<htmlption value="">Select Department</htmlption> <htmlptionsCollection 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
 
Consider Paul's rocket mass heater.
 
subject: problem with html:optionsCollection