File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How can I access hidden value from nested:hidden indexed property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can I access hidden value from nested:hidden indexed property" Watch "How can I access hidden value from nested:hidden indexed property" New topic
Author

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

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
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

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
ThAnks so much Merrill!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How can I access hidden value from nested:hidden indexed property