You could have an anonymous subclass of OgnlList which expects a
String[] in the set(int, Object) method and gets the first String and
calls super.set(index, StrArray[0])

> -----Original Message-----
> From: Jonas Eriksson [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, November 06, 2003 11:55 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [OS-webwork] OGNL list question again
> 
> 
> Ok, thanks for the help.
> I didn't know about the "always use String[] in parameter map" thing.
> 
> The number of input fields are dynamic in my view, and 
> therefore I used 
> the OgnlList.
> 
> I didn't have any luck with adding add(String) or set(int, 
> String) to my 
> List, ognl just uses the set(int, Object obj) method (obj = 
> String[]). I 
> tried using a String[] instead of a List, didn't work. I tried using 
> index getters and setters in my action (instead of returning 
> the list, 
> array), didn't work.
> 
> My solution to this is to create a data placeholder that I put in my 
> OgnlList. By using it I can write
> 
> <input type="text" name="list[1].string" ...
> 
> Cheers
> Jonas
> 
> 
> John Patterson wrote:
> > Form values in the parameter map are always of type 
> String[] even if 
> > they contain only one value.  This is because you may 
> return muliple 
> > values with the same name (ie checkboxs) from an html form.
> > 
> > You do not need to use an OnglList here.  When you use an 
> OgnlList it 
> > is prepopulated with objects so that you can set properties 
> on those 
> > objects. In your example the List is populted with Strings 
> (immutable) 
> > which are then replaced by the String[] value from the 
> parameter map.
> > 
> > You could instead extend List with a add(String) method which would 
> > use XWorks type conversion to use the first String in the array.
> > 
> > John.
> > 
> > ----- Original Message -----
> > From: "Jonas Eriksson" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, November 05, 2003 9:13 PM
> > Subject: [OS-webwork] OGNL list question again
> > 
> > 
> > 
> >>Hi!
> >>
> >>I can not understand why I get arrays (instead of Strings) 
> when OGNL 
> >>populates my list in my action!
> >>
> >>In action:
> >>
> >>// Use OgnlList so we don't get out of bounds
> >>private List theList = new OgnlList(String.class)
> >>
> >>public List getList() {
> >>return theList;
> >>}
> >>
> >>In view:
> >>
> >><input type="text" name="list[1]" size="2" maxlength="2"> <input 
> >>type="text" name="list[2]" size="2" maxlength="2"> and so on...
> >>
> >>Then in my action, theList will contain an array of size 1 
> in position 
> >>1 and 2. Of course I want the string object directly in theList.
> >>
> >>I'm using the latest from cvs. (ww2, xw)
> >>
> >>Thanks
> >>Jonas
> >>
> >>
> >>
> >>-------------------------------------------------------
> >>This SF.net email is sponsored by: SF.net Giveback Program. Does 
> >>SourceForge.net help you be more productive?  Does it
> >>help you create better code?   SHARE THE LOVE, and help us help
> >>YOU!  Click Here: http://sourceforge.net/donate/ 
> >>_______________________________________________
> >>Opensymphony-webwork mailing list 
> >>[EMAIL PROTECTED]
> >>https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
> >>
> > 
> > 
> > 
> > -------------------------------------------------------
> > This SF.net email is sponsored by: SF.net Giveback Program. Does 
> > SourceForge.net help you be more productive?  Does it
> > help you create better code?   SHARE THE LOVE, and help us help
> > YOU!  Click Here: http://sourceforge.net/donate/ 
> > _______________________________________________
> > Opensymphony-webwork mailing list 
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
> > 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program. 
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?   SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/ 
> _______________________________________________
> Opensymphony-webwork mailing list 
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
> 


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to