This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem with html:optionsCollection" Watch "problem with html:optionsCollection" New topic

problem with html:optionsCollection

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 115

I am getting an exception when using validation framework with htmlptionsCollection


<action path="/initProfile"

<forward name="success" path="/pages/createprofile.jsp"/>

<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 name="documentProfile">
<field property="branchId" depends="required">
<msg name="required" bundle="user" key="errors.required" />
<arg bundle="user" key="user.branch" />
<field property="departmentId" depends="required">
<msg name="required" bundle="user" key="errors.required" />
<arg bundle="user" key="user.department" />

<html:form action="/">
<table width="90%" >
<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" />
<td><font color="red"><html:errors bundle="user" property="branchId" ></html:errors></font></td>
<td><bean:message bundle="user" key="user.department"/>
<FONT face=Arial color=#cc0000 size=2><B>*</B></FONT></td>

<html:select property="departmentId" onchange="getDocumentsByDept();" styleId="departmentId" name="documentProfile">
<htmlption value="">Select Department</htmlption> <htmlptionsCollection property="departments" value="departmentId" label="departmentName"/>
<td><font color="red"><html:errors bundle="user" property="departmentId" ></html:errors></font></td>

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
I agree. Here's the link:
subject: problem with html:optionsCollection