Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Topic: finding selected record of nested:iterate using nested:form

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

It need to iterate through an object containing business information. For each business, I need to print out information about the business and also a submit button for "View Details" (similar to rent.com). I'm using nested:iterate, nested:form and nested:submit.

My problem is, when a use clicks on the "View Details" button, how will I be able to know which record was selected. Most importantly, I need to know the businessID of the business the user clicked.

Here's my code:

example of my business object:

SearchResultsDTO results1 = new SearchResultsDTO();
results1.setBusinessID("1708");
results1.setBusinessName("CybexWare Corp.");
results1.setCity("New York");
results1.setState("NY");
results1.setZipCode("84940");
results1.setServiceDetails("lkel ejlj eiel eoi eiu e ieirne euhahiu i rjehio eriherhreihiurh urhiru");

struts-config.xml:

<form-bean name="SearchResultForm" type="org.apache.struts.validator.DynaValidatorForm">
<!-- Dynamic properties of the Search Results Form -->
<form-property name="SearchResultsDTOs" type="java.util.Collection" />
<form-property name="selectedBusiness" type="java.lang.String" />
<form-property name="businessName" type="java.lang.String" />
<form-property name="businessID" type="java.lang.String" />
<form-property name="city" type="java.lang.String" />
<form-property name="state" type="java.lang.String" />
<form-property name="zipCode" type="java.lang.String" />
<form-property name="serviceDetails" type="java.lang.String" />
</form-bean>

My JSP:

<nested:form name="SearchResultForm" action="/searchDetails" type="org.apache.struts.validator.DynaValidatorForm">

<nested:iterate id="searchResults" property="SearchResultsDTOs" indexId="index">

<table width="384" border="0">
<tr>
<td><img width="75" height="85" src="../images/HairHut.bmp"></td>
<td width="327"><table width="327" height="115" border="0">
<tr>
<td width="197">
<table>
<tr>

<td><b><nested:write property="businessName" /></b></td>
</tr>
<tr>
<td><nested:write property="city" />, <nested:write property="state" /> <nested:write property="zipCode" /></td>
</tr>
</table>
</td>
<td width="108" align="right" valign="top">
<nested:submit property="submit" value="View Details"/>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" colspan="2"><nested:write property="serviceDetails" /></td>
</tr>
</table></td>
</tr>
</table>
</nested:iterate>
</nested:form>


ThANks in Advance
 
Marshal
Posts: 67424
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ask questions regarding Struts tags in the Struts forum.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since all you're doing is passing the BusinessId on to the next process, you really don't need all those properties on your ActionForm. You only need one property -- BusinessId.

I'd recommend putting a hidden field in the form, and having each submit button set the ID prior to submitting the form. Something like this:

<html:hidden property="businessId" />
<nested:iterate>
...
<input type="submit" name="saveIt" value="View Details"
onklick="document.myForm.businessId='${searchResults.businessId}';" >
</nested:iterate>

note: the onklick above should be onclick. The JavaRanch filters prevent me from putting it in context.

[ January 11, 2007: Message edited by: Merrill Higginson ]
[ January 11, 2007: Message edited by: Merrill Higginson ]
 
    Bookmark Topic Watch Topic
  • New Topic