Getting lists back from struts

2013-08-07 Thread Fabian Richter

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 ListChoice getChoices() {
 
  }
  
  public ListString 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



smime.p7s
Description: S/MIME Kryptografische Unterschrift


Re: Getting lists back from struts

2013-08-07 Thread Sreekanth S. Nair
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 frich...@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 ListChoice getChoices() {
  
   }
   
   public ListString 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