Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How can I access hidden value from nested:hidden indexed property

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

I'm new to Struts, so I desparately need hElP!!!

I trying to access a hidden value from a nested:hidden indexed property field. However, the hidden value is coming up blank in my ActionForm class. What I'm I doing wrong???

Also, how do I read the "businessID" field in my Action class, if it show up as an indexed array field?

<<<<<<HTML converted nested:hidden>>>>>>>>

<input type="hidden" name="SearchResultForm[0].SearchResultsDTOs[0].businessID" value="8300">

<input type="hidden" name="SearchResultForm[1].SearchResultsDTOs[1].businessID" value="1132">

<<<<<My JSP>>>>>>:

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

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

<table width="384" border="0">
<td><img width="75" height="85" src="../images/HairHut.bmp"></td>
<td width="327"><table width="327" height="115" border="0">
<td width="197">
<nested:hidden property="businessID" indexed="true"/>

<td><b><nested:write property="businessName" /></b><nested:write name="index" /></td>
<td><nested:write property="city" />, <nested:write property="state" /> <nested:write property="zipCode" /></td>
<td width="108" align="right" valign="top">
<bean:message key="button.details" />
<td rowspan="2" colspan="2"><nested:write property="serviceDetails" /></td>



<<<<<MY struts-config>>>>>>>>

<form-bean name="SearchResultForm" type="org.apache.struts.action.DynaActionForm">
<!-- 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" />

<action path="/searchDetails" scope="session" type="com.poshWebApp.action.SearchDetailAction" name="SearchResultForm" input="/web/search/searchResults.jsp" validate="false" >
<forward name="searchDetails" path="/web/search/searchDetail.jsp" redirect="true" />

<action path="/searchResults" scope="session" type="com.poshWebApp.action.SearchDisplayAction" name="SearchResultForm" validate="false" >
<forward name="SearchResults" path="/web/search/searchResults.jsp"/>

<<<<<Action class>>>>>>>>

DynaActionForm form = (DynaActionForm) form_;

String selectedBusiness = form.get("businessID").toString();
ArrayList businessList = (ArrayList)form.get("SearchResultsDTOs") ;
System.out.println("Selected businessID: " + selectedBusiness);
System.out.println("Selected businessName: " + form_ + ", " + form);

Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you have a separate form for each iteration of searchResultDTO, there is a disconnect between the fact that when you submit the form, you only want one businessId to be submitted, but yet you have to set the value of that businessId through iteration and nesting. Because of this, I wouldn't use a struts tag at all for the hidden field. Here's how I'd do it:

<input type="hidden" name="businessId" value='<nested:write property="businessId" />' >

That way Struts doesn't try change your property names to indexed values that don't really fit in this situation, yet the value is still set properly with the <nested:write> tag.
[ January 15, 2007: Message edited by: Merrill Higginson ]
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThAnks so much Merrill!!!
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic