You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Clauss, Arne" <Ar...@gedas.de> on 2003/04/02 10:24:25 UTC
Array of Beans used in an ActionForm
Hello!
Is is possible to deal with an Array of Beans in an AtionForm?
It should look like this:
public class TestForm extends ActionForm {
private DataBean[] dataBeans = DataBean[size_of_array];
getter and setter methods
}
public class DataBean {
private String name="";
private int id = 0;
getter and setter methods
}
Searching the list I have found the following important facts:
- It is important to have an default construktor in the ActionForm, which
creates an instance of the Array.
Have somebody some code example to help me?
Kind regards,
Arne
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Array of Beans used in an ActionForm
Posted by Nicolas De Loof <ni...@cgey.com>.
If you want to use an array for a property that your JSP uses as indexed (i.e. property="data(n)") you will have to
define indexed getters and setters :
public void setData(index i, String value) {
this.data[i] = value;
}
public String getData(index i) {
return this.data[i];
}
Struts will not create an instace of the array for you when it creates or populates the formBean. Your form-bean has to
create the array in the "good" size before population occurs.
Nico.
> Hello!
>
> Is is possible to deal with an Array of Beans in an AtionForm?
>
> It should look like this:
>
> public class TestForm extends ActionForm {
> private DataBean[] dataBeans = DataBean[size_of_array];
>
> getter and setter methods
> }
>
> public class DataBean {
> private String name="";
> private int id = 0;
>
> getter and setter methods
> }
>
> Searching the list I have found the following important facts:
>
> - It is important to have an default construktor in the ActionForm, which
> creates an instance of the Array.
>
> Have somebody some code example to help me?
>
> Kind regards,
>
> Arne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org