You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2010/05/03 08:54:25 UTC
Re: Where is the documentation for Struts tags ....
> Usually the error message you listed means the OGNL expression you
> provided for some argument did not evaluate correctly, thus some
> required piece of information is not available. Please post your tag
> usage again and I'll take a look.
>
It's amazing what a calming effect a weekend and a few beers can have. In
preparing a simplified version of what I was trying to do - everything
clicked into place and at least I've got the checkboxlist displaying now. I
still can't get the selected values back into my action though - the map
selectedroles remains empty. I do have the checkbox interceptor configured.
This is what I've got;
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head></head>
<body>
<s:form>
<s:checkboxlist name="selectedroles" list="%{availableroles}"
value="%{preselectedroles}"/>
<s:submit type="button" label="Add"/>
</s:form>
</body>
</html>
public class Checkbox extends ActionSupport implements Preparable {
/**
*
*/
private Map<String,String> availableroles;
private Map<String,String> selectedroles;
private Map<String,String> preselectedroles;
public String execute() {
return SUCCESS;
}
@Override
public void prepare() throws Exception {
availableroles = new HashMap<String,String>();
availableroles.put("ROLE_USER", "Diagnostics");
availableroles.put("ROLE_ADMIN", "Adminstrator");
availableroles.put("ROLE_UBER", "Unrestricted");
preselectedroles = new HashMap<String,String>();
preselectedroles.put("ROLE_USER", "Diagnostics");
selectedroles = new HashMap<String,String>();
}
public Map<String, String> getAvailableroles() {
return availableroles;
}
public void setAvailableroles(Map<String, String> availableroles) {
this.availableroles = availableroles;
}
public Map<String, String> getSelectedroles() {
return selectedroles;
}
public void setSelectedroles(Map<String, String> selectedroles) {
this.selectedroles = selectedroles;
}
public Map<String, String> getPreselectedroles() {
return preselectedroles;
}
public void setPreselectedroles(Map<String, String> preselectedroles) {
this.preselectedroles = preselectedroles;
}
}
Regards
--
View this message in context: http://old.nabble.com/Where-is-the-documentation-for-Struts-tags-....-tp28413026p28432059.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by Dale Newfield <da...@newfield.org>.
On 5/5/10 9:58 AM, RogerV wrote:
> I'd be happy to contribute
I'd think the best place is:
https://cwiki.apache.org/confluence/display/WW/Struts+2+Form+Tags
I forget what hoops you have to jump through to get a working wiki
account...if it doesn't "just work" when you try to register you might
need to file a "CLA" with someone at apache...or you might just be able
to add a comment anonymously...not sure. See if
https://cwiki.apache.org/confluence/display/WW/Struts+2+Form+Tags?showComments=true&showCommentArea=true#addcomment
works.
> The irony of it all is that I only went with a map originally as I wanted to
> present user-friendly name for ROLE_USER etc.
Yes--although you should suspect pretty much any value provided by the
user, so you want to output the name and key, but upon submission only
expect the key and do a lookup based on that.
> Thanks again Dale
Sure! Best way to pay struts back is to help us with the documentation,
and/or stay subscribed to this list so that you might be able to help
someone else over the same hurdles that you've already cleared.
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by RogerV <ro...@googlemail.com>.
DNewfield wrote:
>
> Sorry you had such difficulty. If you have any specific suggestions for
> the documentation, please help us improve it so that it can better help
> the next person...
>
I'd be happy to contribute my sample .jsp and action.java code that will
illustrate how to get the <s:checkboxlist> tag working with map backed
parameters if you think that would help, and you'd mention where you'd like
it sent.
Longer term I would like to see something like the showcase for the JQuery
plugin that shows working examples and source code for all the tags. The
struts showcase.war doesn't use <s:checkboxlist> at all!
The irony of it all is that I only went with a map originally as I wanted to
present user-friendly name for ROLE_USER etc. If I'd seen the recent thread
http://old.nabble.com/s%3Aselect-help-td28443569.html before I'd started I
might have avoided the pain altogether
Thanks again Dale
--
View this message in context: http://old.nabble.com/Where-is-the-documentation-for-Struts-tags-....-tp28413026p28461295.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by Dale Newfield <da...@newfield.org>.
On 5/5/10 2:57 AM, RogerV wrote:
> The final clue! I changed my jsp to;
>
> <s:checkboxlist name="selectedroles" list="%{availableroles}"
> value="%{preselectedroles}"/>
> 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
Very confusing that everyplace I've seen you have a lower case "r" in
selectedroles, but here it's looking for capital "r"...
> 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.
The framework can be a bit more helpful than that -- if you make that
take an array of Strings it should pre-split them up for you. I'd go
through and make sure you've got your capitalization consistent
everywhere, too.
> 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.
Sorry you had such difficulty. If you have any specific suggestions for
the documentation, please help us improve it so that it can better help
the next person...
> 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.
The tags are really only a server output thing -- is there someplace it
appears to say how the results will come back? Documentation for that
should be wherever the params interceptor is documented. Having that
generate a map would require pairs of linked data coming in with the
request, and I can't think of how that'd happen with standard html tags...
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by RogerV <ro...@googlemail.com>.
Alex Rodriguez Lopez wrote:
>
>
> 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.
>
Yes, you're absolutely correct. Struts will auto-translate a String of comma
seperated values into a List<String> which tidies things up a bit.
Thanks
--
View this message in context: http://old.nabble.com/Where-is-the-documentation-for-Struts-tags-....-tp28413026p28459108.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by Alex Rodriguez Lopez <al...@flordeutopia.pt>.
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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by RogerV <ro...@googlemail.com>.
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
--
View this message in context: http://old.nabble.com/Where-is-the-documentation-for-Struts-tags-....-tp28413026p28457393.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by Dale Newfield <da...@newfield.org>.
On 5/4/10 10:08 AM, RogerV wrote:
>>> <s:checkboxlist name="selectedroles" list="%{availableroles}"
>>> value="%{preselectedroles}"/>
> <input type="checkbox" name="{}" value="ROLE_ADMIN" id="{}-1"/>
> <input type="checkbox" name="{}" value="ROLE_USER" id="{}-2"
> checked="checked"/>
> <input type="checkbox" name="{}" value="ROLE_UBER" id="{}-3"/>
> The rendering is a bit odd, which makes me feel I'm still missing
> something.
Due to the fact that there are three checkboxes with the right values
and the right pre-selection, we know that the list attribute and the
value attribute of the tag are working as desired. The name clearly
isn't working. I've never used a checkboxlist, and I'm unclear as to
how the values are aggregated on submission into the map you desire, but
this brief documentation seems to jive with my understanding that "name"
is usually just that--the name the input tag will use to submit the
field to the server:
"name false false String The name to set for element"
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...
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by RogerV <ro...@googlemail.com>.
DNewfield wrote:
>
> On 5/3/10 2:54 AM, RogerV wrote:
>> <s:form>
>> <s:checkboxlist name="selectedroles" list="%{availableroles}"
>> value="%{preselectedroles}"/>
>> <s:submit type="button" label="Add"/>
>> </s:form>
>
> So what html does this generate for the client to render/submit?
>
The rendering is a bit odd, which makes me feel I'm still missing something.
<tr>
<td class="tdLabel"></td>
<td>
<input type="checkbox" name="{}" value="ROLE_ADMIN" id="{}-1"/>
<label for="{}-1" class="checkboxLabel">Adminstrator</label>
<input type="checkbox" name="{}" value="ROLE_USER" id="{}-2"
checked="checked"/>
<label for="{}-2" class="checkboxLabel">Diagnostics</label>
<input type="checkbox" name="{}" value="ROLE_UBER" id="{}-3"/>
<label for="{}-3" class="checkboxLabel">Unrestricted</label>
<input type="hidden" id="__multiselect_cbox" name="__multiselect_{}"
value="" /> </td>
</tr>
> If you set the form action to be GET it's even easier to see what it is
> submitting. Once you know it's submitting the right set of values, then
> you can focus on where those values go.
>
> This appears in your "prepare"
>> selectedroles = new HashMap<String,String>();
> So if you have params then prepare in your interceptor stack you'll drop
> the values collected in params on the floor. (If you have params
> prepare params, it should come back.)
>
I'm using the params,prepare,params stack.
> I'm not sure how the named values get submitted or how those would get
> converted into a map, so I wonder if this is ever called: (but I admit
> I'm a bit weak on the conversion process)
>
>> public void setSelectedroles(Map<String, String> selectedroles) {
>> this.selectedroles = selectedroles;
>> }
>
> -Dale
>
--
View this message in context: http://old.nabble.com/Where-is-the-documentation-for-Struts-tags-....-tp28413026p28447736.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Where is the documentation for Struts tags ....
Posted by Dale Newfield <da...@newfield.org>.
On 5/3/10 2:54 AM, RogerV wrote:
> <s:form>
> <s:checkboxlist name="selectedroles" list="%{availableroles}"
> value="%{preselectedroles}"/>
> <s:submit type="button" label="Add"/>
> </s:form>
So what html does this generate for the client to render/submit?
If you set the form action to be GET it's even easier to see what it is
submitting. Once you know it's submitting the right set of values, then
you can focus on where those values go.
This appears in your "prepare"
> selectedroles = new HashMap<String,String>();
So if you have params then prepare in your interceptor stack you'll drop
the values collected in params on the floor. (If you have params
prepare params, it should come back.)
I'm not sure how the named values get submitted or how those would get
converted into a map, so I wonder if this is ever called: (but I admit
I'm a bit weak on the conversion process)
> public void setSelectedroles(Map<String, String> selectedroles) {
> this.selectedroles = selectedroles;
> }
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org