wood burning stoves*
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 Android Security Essentials Live Lessons this week in the Android 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: 108

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="/documentProfileAction.do">
<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
jQuery in Action, 2nd edition
subject: problem with html:optionsCollection
Similar Threads
JSP Page when submitted, List becomes empty
How to set values in select box using request scope
Struts 1 :- Two Form submission from one jsp using one submit button
doubt regarding <html:select>
validation error