File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes populating list box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "populating list box" Watch "populating list box" New topic

populating list box

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455

Could somone help me with solving this issue. I couldnt find much help after googling and after searching this forum on JR. I am not sure if im doing something real stupid or not but all the examples i found will throw some exception.

I am trying to display a listbox with some values. This is my action class code

ArrayList myList = new ArrayList();

for( int i=0; i<10 ; i++ )
{ myList.add( new LabelValueBean("Label of "+ i ," value of " +i));

request.getSession().setAttribute( "DisplayList", myList );

In my JSP i have

<bean:define id="answerList" name="QuestionVO" property="DisplayList"
scope="session" type="java.util.ArrayList" />
<html:select name="myForm" property="answerValue" >
<htmlptions collection="answerList" property="label"

When i run the application im getting the following error

ServletException in:/lenderChannel.jsp] Exception creating bean of class java.util.ArrayList: java.lang.ClassCastException: java.util.ArrayList'

Any help is appretiated.

[ October 31, 2006: Message edited by: Rajeev Ravindran ]

SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Remove the <bean:define> tag. You don't need it.

Then specify collection="DisplayList" in your <htmlptions> tag.

Consultant, Sima Solutions
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
Thanks for your reply Merrill. I am more into JSF and now i have to do some enhancement to the exisiting struts app. Your suggestion helped me, i had to define the property in ActionForm too. I may comeup with more silly questions later !

Thanks again,
I agree. Here's the link:
subject: populating list box