struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Struts2 can't populate array property to form beans
Date Mon, 02 Jun 2008 20:43:08 GMT
I would expect that to work. You might try initializing User.phone to an 
empty list and/or fiddling with a -conversion.properties [1] to try and 
coax it into doing the right thing. However, I don't think either of 
those should be necessary.

Double check your log files (and perhaps try up'ing the log level for 
Struts and Xwork to DEBUG); perhaps that will provide some clue as to 
where it's failing.

L.

[1] http://struts.apache.org/2.0.11.1/docs/type-conversion.html

Jacky Shih wrote:
> It is not working even i changed String array to List and append the index
> in the jsp form....
> 
> This method works in Struts1.x...but what should i do to make it functioning
> in Struts 2?
> 
> can anyone help?
> 
> On Mon, Jun 2, 2008 at 11:38 AM, l4kyl4ky@gmail.com <l4kyl4ky@gmail.com>
> wrote:
> 
>> 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
>>
>>
> 


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


Mime
View raw message