• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing parameters to an Action Form

 
Michael Stains
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
<TH>Number_</TH>
<TH>Length_cm</TH>
<TH>Width_cm</TH>
<TH>Height_cm</TH>
<TH>Details</TH>

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

<TD>
<html:submit property="Submit" value="View"></html:submit>
</TD>
</TR>
</html:form>
</logic:iterate>
</TABLE>

Thanks for your help
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic