You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by zafer Mohamed <mz...@yahoo.com> on 2007/02/03 18:40:45 UTC

Populating collection in struts 2 Action properties

I am struggling to populate a collection in the struts action's attribute. My scenario is similiar to below

public class PersonAction extends ActionSupport {

 

private Person person;

public void setPerson(Person 
person){  this.person = person}
public Person getPerson(){  return person}
 

 public String submit() throws Exception {

  return SUCCESS;

 }

}


And my Person class is 

public class Person
{
    private List roles;
    public List getRoles() { return roles; }

    public void setRoles(List roles) { this.roles = roles; }

}

And from my JSP I am trying to populate as below

<s:textfield label="Name" name="person.roles(0).name" />

If someone has a working scenario like this, please send me the todo's to get it working. I have searched the webwork forms and tried most the tricks mentioned there with no luck.

Thanks
Zafer




 
____________________________________________________________________________________
Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html

Re: Populating collection in struts 2 Action properties

Posted by Saul Qunming Yuan <yu...@dataanvil.com>.
Hi,

You may want to try the following:

1. add index-based getter and setter to your Person bean class, i.e.

public Role getRoles(int i) {
    return (Role) getRoles().get(i);
}

public void setRoles(int i, Role role) {
    getRoles().set(i, role);
}

2. use [0] rather than (0) for your name field, i.e

<s:textfield label="Name" name="person.roles[0].name" />


I didn't test it myself, so try it at your own risk :-)


Saul


zafer Mohamed wrote:
> I am struggling to populate a collection in the struts action's attribute. My scenario is similiar to below
>
> public class PersonAction extends ActionSupport {
>
>  
>
> private Person person;
>
> public void setPerson(Person 
> person){  this.person = person}
> public Person getPerson(){  return person}
>  
>
>  public String submit() throws Exception {
>
>   return SUCCESS;
>
>  }
>
> }
>
>
> And my Person class is 
>
> public class Person
> {
>     private List roles;
>     public List getRoles() { return roles; }
>
>     public void setRoles(List roles) { this.roles = roles; }
>
> }
>
> And from my JSP I am trying to populate as below
>
> <s:textfield label="Name" name="person.roles(0).name" />
>
> If someone has a working scenario like this, please send me the todo's to get it working. I have searched the webwork forms and tried most the tricks mentioned there with no luck.
>
> Thanks
> Zafer
>
>
>
>
>  
> ____________________________________________________________________________________
> Sucker-punch spam with award-winning protection. 
> Try the free Yahoo! Mail Beta.
> http://advision.webevents.yahoo.com/mailbeta/features_spam.html
> --------------------------------
> Spam/Virus scanning by CanIt Pro
>
> For more information see
> http://www.kgbinternet.com/SpamFilter.htm
>
> To control your spam filter, log in at
> http://filter.kgbinternet.com
>
>
>   


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


[S2] Re: Populating collection in struts 2 Action properties

Posted by Dave Newton <ne...@yahoo.com>.
--- zafer Mohamed <mz...@yahoo.com> wrote:
> I am struggling to populate a collection in the
> struts action's attribute. 

You neglect to say what the problem actually is, so
helping is... tricky.

> <s:textfield label="Name"
> name="person.roles(0).name" />

As prev. poster said use [0], but this will only work
if you've actually initialize the Person's list of
Roles. Have you? There shouldn't be an issue with what
you're doing, and you do not need indexed get/sets in
S2. (Yaaay, S2/WW!)

d.



 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news

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