struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Angelo zerr" <angelo.z...@gmail.com>
Subject Re: Populate Collection values
Date Mon, 27 Mar 2006 12:14:32 GMT
Hello homas,
To avoid this problem, I use String type in my getter/setter in my Struts
form for any type (Integer, Date,...).
So, you could do that :

public class User {
   String age;
   public String getAge(){
       return age;
   }
   public void setAge(String age){
      this.age=age;
}
}

After you must convert String age into Integer age in your action struts
(after validation), to get values of  list of ages.
Regards
Angelo

2006/3/27, Thomas Otto <otto@strato-rz.de>:
>
> Hello,
> I have the following problem.
>
> I have an struts form with an Collection getter and want to let set
> struts the input values of an submit.
>
> public class UserForm extends ActionForm {
>   // returns a collection of user beans
>    Collection getUsers(){
>    ...
> }
> }
>
> public class User {
>    Integer age;
>    public Integer getAge(){
>        return age;
>    }
>    public void setAge(Integer age){
>       this.age=age;
> }
> }
>
> In the jsp- Page I use layout:collection with layout:text to show the
> input fields in a table.
> <layout:form action="/save">
>        <layout:collection property="users" indexId="index">
>               <layout:collectionItem title="Age" >
>                        <layout:text property="users[${index}].age"
> layout="false"/>
>               </layout:collectionItem>
>    </layout:collection>
> </layout:form>
>
>
> On submit struts fill also all values in the user bean, but struts set
> "0" into the age-Field and not "null" if the value is empty.
> How can I modify this?
>
> Regards
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message