Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nina Anderson
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">
<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>
<nested:hidden property="businessID" indexed="true"/>

<td><b><nested:write property="businessName" /></b><nested:write name="index" /></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">
<html:submit>
<bean:message key="button.details" />
</html:submit>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" colspan="2"><nested:write property="serviceDetails" /></td>
</tr>
</table></td>
</tr>
</table>

</html:form>

</nested:iterate>



<<<<<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" />
</form-bean>

<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>

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


<<<<<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);


HelP!!!
 
Merrill Higginson
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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic