• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

problem with html:optionsCollection

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic