You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Fabian Richter <fr...@mtg.de> on 2013/08/07 15:43:46 UTC
Getting lists back from struts
Hi
I have encountered this issue a couple of times, always found a way to
code around but now I really need to ask:
Can struts create lists/arrays (or whatever collection) when e.g. using
public class MyAction extends ActionSupport {
public List<Choice> getChoices() {
....
}
....
public List<String> getPreSelectedChoices() {
// returns a list of Choice.getKey(), which is a String
....
}
}
public class Choice {
public String getKey() { ...}
public String getDisplayName() { ... }
....
}
<ww:checkboxlist name="myChoice"
list="%{choices}"
listKey="%{'key'}"
listValue="%{'displayName'}"
value="%{preSelectedChoices}" />
The selected values are sent to
public void setMyChoice(String myChoice){
...
}
correct? There is no way somthing like
public void setMyChoice(String[] myChoice){
...
}
works in struts?
If not, whats the common way to get the values back from the String
myChoice? Use Split on it?
Thank you!
Best
Fabian
Re: Getting lists back from struts
Posted by "Sreekanth S. Nair" <sr...@egovernments.org>.
Check this tutorial might help you
http://www.mkyong.com/struts2/how-to-set-default-value-for-multiple-checkboxes-in-struts-2/
--
Thanks & Regards
Srikanth
Software Developer
--------------------------------
eGovernments Foundations
www.egovernments.org
Mob : 9980078913
--------------------------------
On Wed, Aug 7, 2013 at 7:13 PM, Fabian Richter <fr...@mtg.de> wrote:
> Hi
>
> I have encountered this issue a couple of times, always found a way to
> code around but now I really need to ask:
>
> Can struts create lists/arrays (or whatever collection) when e.g. using
>
> public class MyAction extends ActionSupport {
> public List<Choice> getChoices() {
> ....
> }
> ....
> public List<String> getPreSelectedChoices() {
> // returns a list of Choice.getKey(), which is a String
> ....
> }
> }
>
> public class Choice {
> public String getKey() { ...}
> public String getDisplayName() { ... }
> ....
> }
>
> <ww:checkboxlist name="myChoice"
> list="%{choices}"
> listKey="%{'key'}"
> listValue="%{'displayName'}"
> value="%{preSelectedChoices}" />
>
> The selected values are sent to
>
> public void setMyChoice(String myChoice){
> ...
> }
>
> correct? There is no way somthing like
>
> public void setMyChoice(String[] myChoice){
> ...
> }
>
> works in struts?
>
> If not, whats the common way to get the values back from the String
> myChoice? Use Split on it?
>
> Thank you!
>
> Best
> Fabian
>
>