You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steve Akins <ak...@gmail.com> on 2008/04/23 07:36:10 UTC

Passing a List through a hidden field

I have a List called "ids" which contains 4 Strings "22030", "6496",
"6457", "6448"

When the following tag is used:
<s:hidden name="resend.ids" />

It produces the following HTML:

<input type="hidden" name="resend.ids" value="[22030, 6496, 6457,
6448]" id="/test/resend_resend_ids"/>


When the form is submitted the "ids" List is populated with one String
"[22030, 6496, 6457, 6448]" instead of 4 Strings "22030", "6496",
"6457", "6448".


This looks like a problem with how the XWorkBasicConverter is working
or I have just not figured out how to do this yet.

I would have thought that there's support for passing a List through a
form without the need for creating a custom converter for this.

Does anyone have any ideas on how to overcome this problem?


Regards,
Steve

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


Re: Passing a List through a hidden field

Posted by Gabriel Belingueres <be...@gmail.com>.
But it translates the List into a meaningful string because the
contents are Strings or Integers, but what about other objects that
doesn't override the toString() method?

Anyway, I suppose you could write a custom type converter for your
List, but I think the current multiple hidden fields solution is fine
too.

2008/4/23, Steve Akins <ak...@gmail.com>:
> Thanks Gabriel and Jeromy,
>
> I had thought of iterating through the List but was trying to avoid
> generating a mass of HTML hidden fields.
>
> I like it how the hidden tag translates the List into a meaningful
> String, it's just a shame that Struts/XWork doesn't handle it when the
> form is submitted.
>
> I have raised an Improvement request on the JIRA
> (https://issues.apache.org/struts/browse/WW-2612) and will continue to
> investigate a way around this.  If anyone else has some bright ideas
> it would be more than welcome.
>
> Regards,
> Steve
>
> On Wed, Apr 23, 2008 at 10:57 PM, Jeromy Evans
> <je...@blueskyminds.com.au> wrote:
> >
> > Steve Akins wrote:
> >
> > > I have a List called "ids" which contains 4 Strings "22030", "6496",
> > > "6457", "6448"
> > >
> > > When the following tag is used:
> > > <s:hidden name="resend.ids" />
> > >
> > > It produces the following HTML:
> > >
> > > <input type="hidden" name="resend.ids" value="[22030, 6496, 6457,
> > > 6448]" id="/test/resend_resend_ids"/>
> > >
> > >
> > > When the form is submitted the "ids" List is populated with one String
> > > "[22030, 6496, 6457, 6448]" instead of 4 Strings "22030", "6496",
> > > "6457", "6448".
> > >
> > >
> > > This looks like a problem with how the XWorkBasicConverter is working
> > > or I have just not figured out how to do this yet.
> > >
> > > I would have thought that there's support for passing a List through a
> > > form without the need for creating a custom converter for this.
> > >
> > > Does anyone have any ideas on how to overcome this problem?
> > >
> > >
> > > Regards,
> > > Steve
> > >
> > >
> > >
> >  Hi Steve,
> >
> >  I've seen this before but didn't have time to investigate.  I just split
> > the string into an array in my action.
> >  I agree it should work as you've described without a custom converter. But
> > doesn't. Or doesn't always. Or doesn't give enough feedback about why it
> > didn't.  If you have time, it would be helpful if you can see if an issue
> > exists in JIRA and if not create one.
> >
> >  regards,
> >  Jeromy Evans
> >
> >
> >
> >
> >  ---------------------------------------------------------------------
> >  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
>
>

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


Re: Passing a List through a hidden field

Posted by Steve Akins <ak...@gmail.com>.
Thanks Gabriel and Jeromy,

I had thought of iterating through the List but was trying to avoid
generating a mass of HTML hidden fields.

I like it how the hidden tag translates the List into a meaningful
String, it's just a shame that Struts/XWork doesn't handle it when the
form is submitted.

I have raised an Improvement request on the JIRA
(https://issues.apache.org/struts/browse/WW-2612) and will continue to
investigate a way around this.  If anyone else has some bright ideas
it would be more than welcome.

Regards,
Steve

On Wed, Apr 23, 2008 at 10:57 PM, Jeromy Evans
<je...@blueskyminds.com.au> wrote:
>
> Steve Akins wrote:
>
> > I have a List called "ids" which contains 4 Strings "22030", "6496",
> > "6457", "6448"
> >
> > When the following tag is used:
> > <s:hidden name="resend.ids" />
> >
> > It produces the following HTML:
> >
> > <input type="hidden" name="resend.ids" value="[22030, 6496, 6457,
> > 6448]" id="/test/resend_resend_ids"/>
> >
> >
> > When the form is submitted the "ids" List is populated with one String
> > "[22030, 6496, 6457, 6448]" instead of 4 Strings "22030", "6496",
> > "6457", "6448".
> >
> >
> > This looks like a problem with how the XWorkBasicConverter is working
> > or I have just not figured out how to do this yet.
> >
> > I would have thought that there's support for passing a List through a
> > form without the need for creating a custom converter for this.
> >
> > Does anyone have any ideas on how to overcome this problem?
> >
> >
> > Regards,
> > Steve
> >
> >
> >
>  Hi Steve,
>
>  I've seen this before but didn't have time to investigate.  I just split
> the string into an array in my action.
>  I agree it should work as you've described without a custom converter. But
> doesn't. Or doesn't always. Or doesn't give enough feedback about why it
> didn't.  If you have time, it would be helpful if you can see if an issue
> exists in JIRA and if not create one.
>
>  regards,
>  Jeromy Evans
>
>
>
>
>  ---------------------------------------------------------------------
>  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: Passing a List through a hidden field

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Steve Akins wrote:
> I have a List called "ids" which contains 4 Strings "22030", "6496",
> "6457", "6448"
>
> When the following tag is used:
> <s:hidden name="resend.ids" />
>
> It produces the following HTML:
>
> <input type="hidden" name="resend.ids" value="[22030, 6496, 6457,
> 6448]" id="/test/resend_resend_ids"/>
>
>
> When the form is submitted the "ids" List is populated with one String
> "[22030, 6496, 6457, 6448]" instead of 4 Strings "22030", "6496",
> "6457", "6448".
>
>
> This looks like a problem with how the XWorkBasicConverter is working
> or I have just not figured out how to do this yet.
>
> I would have thought that there's support for passing a List through a
> form without the need for creating a custom converter for this.
>
> Does anyone have any ideas on how to overcome this problem?
>
>
> Regards,
> Steve
>
>   
Hi Steve,

I've seen this before but didn't have time to investigate.  I just split 
the string into an array in my action.
I agree it should work as you've described without a custom converter. 
But doesn't. Or doesn't always. Or doesn't give enough feedback about 
why it didn't.  If you have time, it would be helpful if you can see if 
an issue exists in JIRA and if not create one.

regards,
 Jeromy Evans


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


Re: Passing a List through a hidden field

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Gabriel Belingueres wrote:
> You need to iterate the list with an status variable and produce
> hidden fields of the following form:
>
> <s:hidden name="resend.ids[%{#status.index}]" />
>
>   
Yeah, that works.  It's a pity that OGNL's conversion from list/array to 
string doesn't output a string that can be converted back into an 
array/list.


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


Re: Passing a List through a hidden field

Posted by Gabriel Belingueres <be...@gmail.com>.
You need to iterate the list with an status variable and produce
hidden fields of the following form:

<s:hidden name="resend.ids[%{#status.index}]" />

2008/4/23, Steve Akins <ak...@gmail.com>:
> I have a List called "ids" which contains 4 Strings "22030", "6496",
> "6457", "6448"
>
> When the following tag is used:
> <s:hidden name="resend.ids" />
>
> It produces the following HTML:
>
> <input type="hidden" name="resend.ids" value="[22030, 6496, 6457,
> 6448]" id="/test/resend_resend_ids"/>
>
>
> When the form is submitted the "ids" List is populated with one String
> "[22030, 6496, 6457, 6448]" instead of 4 Strings "22030", "6496",
> "6457", "6448".
>
>
> This looks like a problem with how the XWorkBasicConverter is working
> or I have just not figured out how to do this yet.
>
> I would have thought that there's support for passing a List through a
> form without the need for creating a custom converter for this.
>
> Does anyone have any ideas on how to overcome this problem?
>
>
> Regards,
> Steve
>
> ---------------------------------------------------------------------
> 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