Em 05-05-2010 07:57, RogerV escreveu:



So if it's looking for a string, let's make sure you're giving it one,
and not the .toString of an empty map that it got from your prepare method:

<s:checkboxlist name="%{'selectedroles'}" list="%{availableroles}"
value="%{preselectedroles}"/>

I must admit I don't understand what you expect this to submit, or how
that should become a map -- there are only one set of values, not
pairs...Even if you get this to render the html I'm guessing that you
expect:

<input type="checkbox" name="selectedroles" value="ROLE_ADMIN"
id="selectedroles-1"/>
<input type="checkbox" name="selectedroles" value="ROLE_USER"
id="selectedroles-2" checked="checked"/>
<input type="checkbox" name="selectedroles" value="ROLE_UBER"
id="selectedroles-3"/>

I don't see how you'd get a map out of that.  You could get a String[]
easily, which would be the ROLE_ values that were checked...



The final clue! I changed my jsp to;

<s:checkboxlist name="selectedroles" list="%{availableroles}"
value="%{preselectedroles}"/>

which gives me a much more sensible looking Html representation:

<input type="checkbox" name="selectedroles" value="ROLE_ADMIN"
id="selectedroles-1"/>
<label for="selectedroles-1" class="checkboxLabel">Adminstrator</label>
<input type="checkbox" name="selectedroles" value="ROLE_USER"
id="selectedroles-2" checked="checked"/>
<label for="selectedroles-2" class="checkboxLabel">Diagnostics</label>
<input type="checkbox" name="selectedroles" value="ROLE_UBER"
id="selectedroles-3"/>
<label for="selectedroles-3" class="checkboxLabel">Unrestricted</label>
<input type="hidden" id="__multiselect_checkbox_selectedroles"
name="__multiselect_selectedroles" value="" />

Now when I submit the form, after changing the form method to GET so I can
look at what is submitted with HttpHeaders (why I never thought of that
before?) and I see that

checkbox?selectedroles=ROLE_ADMIN&selectedroles=ROLE_USER&selectedroles=ROLE_UBER&__multiselect_selectedroles=

is sent. I saw an exception being thrown "No such method for
setSelectedRoles(String) and the message
"Invalid field value for field selectedRoles" displayed in the web-page,
which must be coming from the checkbox handling routines as it certainly
isn't coming from me.

So I changed the method setSelectedRoles(Map<String,String>  selectedRoles)
to setSelectedRoles(String selectedRoles) and stuck the debugger on it, and
what comes back is, as you suspected all along, a string value that contains
a comma separated list of the selected values ie
ROLE_ADMIN,ROLE_USER,ROLE_UBER which I can easily split&  shove back into
the map of selected Roles.

Phew! I would never have worked that one out without your help and I
certainly wouldn't have worked it out from the available documentation.
Either checkboxlist will not return a map under any circumstances, in which
case the documentation should say so, or there is a way of forcing the name
attribute to evaluate to something that Struts would interpret as a map
entry that I haven't worked out yet.

Thanks a million

Regards


Roger,
you can use a list as setSelectedRoles(List<String> selectedRoles) that will get filled with multiple Strings, this way you can iterate it easily without having to split the comma separated string.

Regards

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

Reply via email to