struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "l4kyl4ky@gmail.com" <l4kyl...@gmail.com>
Subject Re: Struts2 can't populate array property to form beans
Date Mon, 02 Jun 2008 03:38:08 GMT
try using List,

public class User {
       //String [] phone;
        private List <String> phone;

    public List<String> getPhone() {
        return phone;
    }

    public void setPhone(List<String> phone) {
        this.phone = phone;
    }
      
}

the JSP
<form name="XXX" action="XXX">
      <input type=text name="user.phone[0]" />
      <input type=text name="user.phone[1]" />
      <input type=text name="user.phone[2]" />
       <input type=submit name=submit value=submit/>
</form>


And the action

U didn't have to f this 
>>>>>>>>> private User user=new User();

just

    private User user;
    public User getUser(){ return user;}
    public void setUser(User user) { this.user=user;}


        Iterator it = getUser().getPhone().iterator();
        while (it.hasNext()) {
            Object object = it.next();
            System.out.print(object);
        }

Jacky Shih wrote:
> Hi all,
>
> I meet a problem on populating array properties...
> here is the detail description:
>
> public class User {
>        String [] phone;
>        public String[] getPhone(){
>              return phone;
>        }
>        public void setPhone(String[] phone) {
>              this.phone=phone;
>        }
> }
>
> public class UserAction {
>         private User user=new User();
>
>         public User getUser(){ return user;}
>         public void setUser(User user) { this.user=user;}
>
>         public String execute() {
>                   // user.getPhone() always return null...
>         }
>
> }
>
>
> And i have a jsp which will submit a list of phone to the action class
>
>
> <form name=xxx action=xxx>
>       <input type=text name="user.phone" />
>       <input type=text name="user.phone" />
>       <input type=text name="user.phone" />
>        <input type=submit name=submit value=submit/>
> </form>
>
>
> after the form is submitted... the action class is called, however the list
> of phone can't be populated to the user object in the UserAction class...
> i have tried if the phone is not a array type.. the property is populated to
> the user object ...
> any suggestion for the issue?
> thx alot!
>
>   


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


Mime
View raw message