struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Reumann" <>
Subject Re: Some extra eyes to see where I'm screwing this code up...(form with Map property where keys-String, values-String[])
Date Mon, 24 Apr 2006 19:30:45 GMT
Ok, figured out the below.

I remember running into this before and I should have remembered it.
For those reading this from the archives at some late date...

it really helps if you use regular pojos as values for your Maps.
These pojos can thus have the proper getter/setters for access to the
type of object you really care about as storing as your map values.

When I nested the String[] inside of a "Roles" object (with String[]
getRoles method and setter) and then stuffed the "Roles' object as the
value for each key in the map, things work fine.

so instead of


I have


and everything is fine (and I did need to use the reset method to
reset the String[] object in the Roles object since I decided to use
Session scope because didn't feel like using Lazy objects).

On 4/24/06, Rick Reumann <> wrote:
> Thanks for any help...
> Here's what the html page output looks like:
> Product Roles
> -------------
> SomeProduct
> SomeProduct2
> SomeProduct3
> Backing this output is an ActionForm with the property:
> HashMap productRolesMap;
> //there is also a Map with this same name put into
> //request scope
> The ActionForm map has the keys set to the "productId" (number as a String)
> and the value is a String[]. When the form submits I just want to
> have the form's productRolesMap set with the String[] of the
> selected roles. (Since these aren't boolean properties, all I need
> is the values of the selected items).
> Below is the code I was trying to use and it's working fine for
> displaying the intial set of information (correct items are checked
> and unchecked). The problem is when it submits, the String[] arrays in
> the Map are not being updated at all.
> The setter for the productRolesMap is called, but apparently the new
> values selected are not being reflected in this Map.
> The code I'm working with:
> <c:forEach var="productMapItem" items="${productRolesMap}" varStatus="pStatus">
>     <b>${productMapItem.key.productName}</b>
>     <div style="padding-left:15px;">
>         <c:forEach var="role" items="${productMapItem.value}">
>             <html:multibox name="authenticateForm"
>                  property="productRolesMap.${productMapItem.key.productId}">
>                     ${role}
>             </html:multibox>
>             ${role}&nbsp;&nbsp;
>         </c:forEach>
>     </div>
>     <br/><br/>
> </c:forEach>
> A snippet of the resulting html looks like:
> <input type="checkbox" name="productRolesMap.2" value="INTERNALAUTHOR">
> <input type="checkbox" name="productRolesMap.2" value="EXTERNALAUTHOR"
> checked="checked">
> I'm sure it's something stupid that I'm doing wrong. (Isn't it always:)
> --
> Rick


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message