wood burning stoves 2.0*
The moose likes Struts and the fly likes how to set arraylist in formbean and display the same values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to set arraylist in formbean and display the same values in jsp" Watch "how to set arraylist in formbean and display the same values in jsp" New topic
Author

how to set arraylist in formbean and display the same values in jsp

a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82

I have an action class, in which i read values from DB. i want to display those values in jsp using <html:select> as a listbox.

for this:
1)i declared one arraylist called statuslist in my formbean
2)im setting those retrieved values in action class to this arraylist like this.
while(rs.next())
{
fmActionForm = new FileManagementActionForm();
status = rs.getString("status");
statusList.add(status);
fmActionForm.setStatuslist(statusList);
}
3)in jsp, i try to display using <html:select> like this
<html:select property="selectedstatus" styleClass="select">
<htmlptions collection="statuslist" labelProperty="status" property="status"/>
</html:select>

i didnt use any session object to set and get in jsp for the arraylist.

Im getting error as: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean under name statuslist

can anybody tell me am i doing correctly or not?

thanks in advance,
kishore
Ranveer K Kumar
Ranch Hand

Joined: Sep 13, 2009
Posts: 64
a kishore wrote:

while(rs.next())
{
fmActionForm = new FileManagementActionForm();
status = rs.getString("status");
statusList.add(status);
fmActionForm.setStatuslist(statusList);
}
<html:select property="selectedstatus" styleClass="select">
<htmlptions collection="statuslist" labelProperty="status" property="status"/>
</html:select>








try above..
if not run then let me know the form and action in more details..
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Thanks for your reply Ranveer,

i observed that you commented the line



in while loop. If i do so, the arraylist is storing only the last value when displaying in jsp.

my another doubt is, do i need to use session object to set arraylist in action class ? bcuz i use the following code to set arraylist in session. if i didnt put that in session, i couldnt get arraylist in jsp. it is throwing null pointer exception. any solution without session objects?

here is my code to set arraylist in session, in my action class



and my struts-config.xml action mapping is this:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set arraylist in formbean and display the same values in jsp