• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

populating list box

 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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"
labelProperty="label"/>
</html:select>


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.

Thanks,
Rajeev
[ October 31, 2006: Message edited by: Rajeev Ravindran ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the <bean:define> tag. You don't need it.

Then specify collection="DisplayList" in your <htmlptions> tag.
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Rajeev
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic