Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Populating select boxes from Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Populating select boxes from Database" Watch "Populating select boxes from Database" New topic
Author

Populating select boxes from Database

Balegar Chandrappa Dinesh
Greenhorn

Joined: Mar 14, 2002
Posts: 3
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

Joined: Apr 23, 2002
Posts: 168
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populating select boxes from Database