struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Reumann" <ric...@gmail.com>
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

 property="productRolesMap.${productMapItem.key.productId}">

I have

 property="productRolesMap.${productMapItem.key.productId}.roles">

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 <rickcr@gmail.com> wrote:
> Thanks for any help...
>
> Here's what the html page output looks like:
>
> Product Roles
> -------------
>
> SomeProduct
>     [] INTERNALAUTHOR    []EXTERNALAUTHOR
>
> SomeProduct2
>     [] INTERNALAUTHOR    []EXTERNALAUTHOR
>
> SomeProduct3
>     [] INTERNALAUTHOR    []EXTERNALAUTHOR
>
>
> 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">
> INTERNALAUTHOR
>
>
> <input type="checkbox" name="productRolesMap.2" value="EXTERNALAUTHOR"
> checked="checked">
> EXTERNALAUTHOR
>
> I'm sure it's something stupid that I'm doing wrong. (Isn't it always:)
>
> --
> Rick
>


--
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message