• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating select boxes from Database

 
Balegar Chandrappa Dinesh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using database top populate a select box in the JSP. First time when the JSP is called, the select box is populated correctly.
I use the following code for this:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
<bean efine id="selProject" name="projectsForm" property="selProject" type="java.util.ArrayList"/>
<html:select property="selProject" size="10" style="width:180px" onchange="projectsOnChange();">
<html ptions collection="selProject" property="value" labelProperty="label" />
</html:select>
-----------------------------------------------------------------------------------------------------------------------------------------------------------
"selProject" is an attribute in my form bean which is of type ArrayList. This array list contains objects of type
OptionLabelValue.
When i click the save button the following error occurs.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
exception
javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:774)
at org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:2061)
...........
root cause
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...........
-----------------------------------------------------------------------------------------------------------------------------------------------------------
All my form beans are in request scope.
Any suggestions please.
regards,
Dinesh
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is at <html:select property="selProject" ...
This property needs to hold whatever item was selected, not an ArrayList. So you probably need to add an attribute to your form bean to hold whatever value was selected, and change the property attribute of your select tag accordingly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic