You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy Chapman <an...@brighterworking.com> on 2010/09/04 02:58:49 UTC

How do I get wibble[0][something]=blah to parse into an action?

  I've got a 3rd party javascript tool that posts parameters like:

wibble[0][something] = /babble
wibble[0][foo] = 3
wibble[0][bar] = seventeen
wibble[1][something] = /bloop
wibble[1][foo] = 12
wibble[1][bar] = Only on Wednesdays

I can't figure out how to get the ParametersInterceptor to put the 
values it into my setter.
I've tried all sorts of things, but the [something] is failing to get 
through. My best effort was something like this,

public MyActionClass extends ActionSupport {

     ArrayList<Map<String, String>> wibble = null;

<...execute etc. don't really matter...>

     public ArrayList<Map<String, String>> getWibble() {
         if (this.wibble==null) {
             this.wibble = new ArrayList<Map<String, String>>();
         }
         return this.wibble;
     }

     public void setWibble(ArrayList<Map<String, String>> wibble) {
         this.wibble = wibble;
     }
}

In debug I can see the struts2 innards calling getWibble for each post 
parameter and creating the 0'th or 1'th element of the ArrayList but 
then it seems to resolve [something] by looking for a property or method 
(setSomething?) on the MyActionClass instance in the context rather than 
the ArrayList instance it got previously (which never goes into the 
context).

Obviously, I can make the action RequestAware and parse out the 
parameters myself or write/extend an interceptor, but it would be nice 
to have the base ParameterInterceptor and OGNL do it .

Any ideas?

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


AW: How do I get wibble[0][something]=blah to parse into an action?

Posted by Nicolas Kopp <Ni...@empirica.com>.
Hi Andy,

maybe you forgot to initialize the ArrayList as a new Object in the setter?

try this:

     public void setWibble(ArrayList<Map<String, String>> wibble) {
		this.wibble = new ArrayList<Map<String,String>>();
		this.wibble = wibble;
     }

Maybe worth a try. Not tested.

Cheers,
Nico


-----Ursprüngliche Nachricht-----
Von: Andy Chapman [mailto:andrew.chapman@brighterworking.com] 
Gesendet: Samstag, 4. September 2010 02:59
An: user@struts.apache.org
Betreff: How do I get wibble[0][something]=blah to parse into an action?

  I've got a 3rd party javascript tool that posts parameters like:

wibble[0][something] = /babble
wibble[0][foo] = 3
wibble[0][bar] = seventeen
wibble[1][something] = /bloop
wibble[1][foo] = 12
wibble[1][bar] = Only on Wednesdays

I can't figure out how to get the ParametersInterceptor to put the 
values it into my setter.
I've tried all sorts of things, but the [something] is failing to get 
through. My best effort was something like this,

public MyActionClass extends ActionSupport {

     ArrayList<Map<String, String>> wibble = null;

<...execute etc. don't really matter...>

     public ArrayList<Map<String, String>> getWibble() {
         if (this.wibble==null) {
             this.wibble = new ArrayList<Map<String, String>>();
         }
         return this.wibble;
     }

     public void setWibble(ArrayList<Map<String, String>> wibble) {
         this.wibble = wibble;
     }
}

In debug I can see the struts2 innards calling getWibble for each post 
parameter and creating the 0'th or 1'th element of the ArrayList but 
then it seems to resolve [something] by looking for a property or method 
(setSomething?) on the MyActionClass instance in the context rather than 
the ArrayList instance it got previously (which never goes into the 
context).

Obviously, I can make the action RequestAware and parse out the 
parameters myself or write/extend an interceptor, but it would be nice 
to have the base ParameterInterceptor and OGNL do it .

Any ideas?

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


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


Re: How do I get wibble[0][something]=blah to parse into an action?

Posted by Rahul Mohan <ra...@tcs.com>.
Hi Andy,

This seems to be a problem with S2. ( See: 
http://struts-2.464677.n5.nabble.com/Ognl-problem-td1672158.html#a1672158 
and http://www.mail-archive.com/user@struts.apache.org/msg96386.html ). I 
struggled with this for some time but finally went ahead with a 
work-around - changed the list<map> to a list of a new container class 
which has the map in it (see code below).

private List<RowData>; 

class RowData {
 private Map<String,Object> cellData;
}

- Rahul



From:
Andy Chapman <an...@brighterworking.com>
To:
user@struts.apache.org
Date:
04-09-2010 06:29
Subject:
How do I get wibble[0][something]=blah to parse into an action?



  I've got a 3rd party javascript tool that posts parameters like:

wibble[0][something] = /babble
wibble[0][foo] = 3
wibble[0][bar] = seventeen
wibble[1][something] = /bloop
wibble[1][foo] = 12
wibble[1][bar] = Only on Wednesdays

I can't figure out how to get the ParametersInterceptor to put the 
values it into my setter.
I've tried all sorts of things, but the [something] is failing to get 
through. My best effort was something like this,

public MyActionClass extends ActionSupport {

     ArrayList<Map<String, String>> wibble = null;

<...execute etc. don't really matter...>

     public ArrayList<Map<String, String>> getWibble() {
         if (this.wibble==null) {
             this.wibble = new ArrayList<Map<String, String>>();
         }
         return this.wibble;
     }

     public void setWibble(ArrayList<Map<String, String>> wibble) {
         this.wibble = wibble;
     }
}

In debug I can see the struts2 innards calling getWibble for each post 
parameter and creating the 0'th or 1'th element of the ArrayList but 
then it seems to resolve [something] by looking for a property or method 
(setSomething?) on the MyActionClass instance in the context rather than 
the ArrayList instance it got previously (which never goes into the 
context).

Obviously, I can make the action RequestAware and parse out the 
parameters myself or write/extend an interceptor, but it would be nice 
to have the base ParameterInterceptor and OGNL do it .

Any ideas?

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



=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you