what about:
<input type="text" name="createEmail('business').address"/>
public Email createEmail(String type)
{
Email result = new Email();
result.setType(type);
_emails.put(type, result);
return result;
}
the solution below would create the first email at index 1 even if you
specify index should be 3 (ie not a sparse array). If you always retrieve
it with the name you will get the correct object.
John.
----- Original Message -----
From: "Matt Ho" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 03, 2003 8:14 AM
Subject: Re: RES: [OS-webwork] Same property, 3 textfields
> Try this. This should work.
>
> class MyAction ... {
> private List emails = new OgnlList();
> public List getEmails() { return this.emails ; }
> ...
> }
>
> class OgnlList extends ArrayList {
> private Class clazz;
>
> public OgnlList(Class clazz) {
> this.clazz = clazz;
> }
>
> public synchronized Object get(int index) {
> while (index >= this.size()) {
> try {
> this.add(clazz.newInstance());
> } catch (Exception e) {
> throw new RuntimeException(e);
> }
> }
> return super.get(index);
> }
> }
>
> Methinks we should probably include this OgnlList somewhere in XWork.
>
> M
>
> [EMAIL PROTECTED] wrote:
>
> > Hi Jason!
> >
> > I tried this:
> >
> > #bodytag(Form "action=emails.action" "method=post")
> > #tag(TextField "label='E-mail'" "name=emails[0].address")
> > #tag(TextField "label='E-mail'" "name=emails[1].address")
> > #tag(TextField "label='E-mail'" "name=emails[2].address")
> > #tag(Submit "value='Continue'");
> > #end
> >
> > And it rightly throws an IndexOutOfBounds excecption trying to call
> > AddEmailsAction.getEmails().get(0), .get(1), and get(2) even before
> > letting me set the fields. So, I'm pretty sure this implementation won't
> > work well, but I'm out of ideas... do you have any? I'm free to
> > implement anything that might be needed, my only requirements are to
> > have a List of Email objects when the action finishes execute().
> >
> > Again, thanks for the help! :)
> >
> > -cv
> >
> >
> > -----Mensagem original-----
> > De: Jason Carreira [mailto:[EMAIL PROTECTED]
> > Enviada em: quinta-feira, 2 de outubro de 2003 16:27
> > Para: [EMAIL PROTECTED]
> > Assunto: RE: [OS-webwork] Same property, 3 textfields
> >
> >
> > Hmm... what is that syntax for indexed properties... try field names
> > email(1).address and email(1).type, etc...
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, October 02, 2003 3:24 PM
> > To: [EMAIL PROTECTED]
> > Subject: [OS-webwork] Same property, 3 textfields
> >
> >
> > Hi everyone! :)
> > I've got a form like this:
> > E-mail: [ [EMAIL PROTECTED] ] Type: [Personal ][v]
> > E-mail: [ [EMAIL PROTECTED] ] Type: [Business ][v]
> > E-mail: [ ] Type: [Other ][v]
> > , an Email object:
> > public class Email {
> > private String address;
> > private int type;
> > // getters and setters
> > }
> > , and a List of Email objects in my Action:
> > public class AddEmailsAction extends ActionSupport {
> > private List emails = new ArrayList();
> > // getters and setters
> > }
> > How can I make WW2 add a new Email object for each row filled in the
> > form? Is it even possible? :)
> > Peace,
> > -cv
> >
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Opensymphony-webwork mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
>
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork