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

Passing parameters to an Action Form

Michael Stains

Joined: Mar 07, 2008
Posts: 5
Hi, I am displaying a list of items on a JSP page using Struts. I want to be able to select an item from the list to display more information about the item in another page. To display the items details on the second page I need to know what the ITEM_NUMBER is so that I can retieve the Item details in the Action Form and pass the data to the new JSP page. What is the best method to achieve this whist preserving the Struts MVC architecture. Below is an example of the first JSP page displaying a list of Items ready for selection:

<TABLE border="1" width="100%">
<TR class="pm2">

<logic:iterate name="listitemsBean" property="listitems_rows" scope="request" id="listitemsRow">
<html:form action="/DetailsOfanItem">
<TD><bean:write name="listitemsRow" property="ITEM_NUMBER" />
<TD><bean:write name="listitemsRow" property="LENGTH_CM" />
<TD><bean:write name="listitemsRow" property="WIDTH_CM" />
<TD><bean:write name="listitemsRow" property="HEIGHT_CM" />

<html:submit property="Submit" value="View"></html:submit>

Thanks for your help
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Hello Michael, welcome to JavaRanch.

This code just converts everything into dumb html. Moreover, since your bean has a number of itemrows so you can't directly identify which element ws selected by user. Which in turn means that you can't get your value(ITEM_NUMBER) directly form <bean:write ...../>

You should enclose your code in a <html:form/> tag and pass the ITEM_NUMBER property as a html input to the actionform.

Else, you can associate a <html:hidden/> element uniquely for every "listitemsRow" object and pass that to your action.

What I mean is

Hope this helps.
[ March 07, 2008: Message edited by: Anubhav Anand ]
I agree. Here's the link:
subject: Passing parameters to an Action Form
It's not a secret anymore!