You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sylvain ~ <sy...@gmail.com> on 2005/01/28 08:55:34 UTC
Abstract Bean Processing
Hi,
I wanted to create a Form Bean to represent a list of StorableObjects
with a filter bean nested inside in order to be able to handle
generically list display of Objects.
Here is my ListBean code :
public class ListBean extends ActionForm {
private ArrayList l;
private StorableObject filter;
public void setList(ArrayList l){
this.l = l;
}
public ArrayList getList(){
return l;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public StorableObject getFilter() {
return filter;
}
public void setFilter(StorableObject filter) {
this.filter = filter;
}
}
The objects are stored in the list property of the bean, and filter
parameters are stored in filter property.
The StorableObject Class is abstract, and thus doesn't have any
properties, implementing classes have such properties accessors. Form
population with the right class type is made at runtime by the action.
When submitting the filter form, I get a
javax.servlet.ServletException: BeanUtils.populate exception, despite
I am able to display values populated by the action.
It seems that in this case Struts tries to populate a bean of type
StorableObject, and since this one is abstract it results in a error.
So, my question, is there a way to make struts use a generic form bean
with any properties names and values and then handle it by hand in the
action ?
Any input would be appreciated.
Sylvain.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Abstract Bean Processing
Posted by Hubert Rabago <hr...@gmail.com>.
Instead of using the StorableObject in your form bean, use a
LazyDynaBean, then when the form gets submitted, use
BeanUtils.copyProperties to copy from the LazyDynaBean to your
concrete StorableObject instances.
Hubert
On Fri, 28 Jan 2005 16:55:34 +0900, Sylvain ~ <sy...@gmail.com> wrote:
<snip/>
> Here is my ListBean code :
>
> public class ListBean extends ActionForm {
>
> private ArrayList l;
> private StorableObject filter;
>
<snip/>
> The StorableObject Class is abstract, and thus doesn't have any
> properties, implementing classes have such properties accessors. Form
> population with the right class type is made at runtime by the action.
>
<snip/>
> So, my question, is there a way to make struts use a generic form bean
> with any properties names and values and then handle it by hand in the
> action ?
>
> Any input would be appreciated.
> Sylvain.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Abstract Bean Processing
Posted by li...@gmx.net.
Hi Silvian,
you have to know the propertyname and write accessor-methods. Where
should struts know, which property to put out?
Have a look at the jstl-core library.
Greets Mark
Sylvain ~ wrote:
>Hi,
>
>I wanted to create a Form Bean to represent a list of StorableObjects
>with a filter bean nested inside in order to be able to handle
>generically list display of Objects.
>
>Here is my ListBean code :
>
>public class ListBean extends ActionForm {
>
> private ArrayList l;
> private StorableObject filter;
>
> public void setList(ArrayList l){
> this.l = l;
> }
>
> public ArrayList getList(){
> return l;
> }
>
> public Integer getId() {
> return id;
> }
> public void setId(Integer id) {
> this.id = id;
> }
>
>
> public StorableObject getFilter() {
> return filter;
> }
> public void setFilter(StorableObject filter) {
> this.filter = filter;
> }
>}
>
>The objects are stored in the list property of the bean, and filter
>parameters are stored in filter property.
>
>The StorableObject Class is abstract, and thus doesn't have any
>properties, implementing classes have such properties accessors. Form
>population with the right class type is made at runtime by the action.
>
>When submitting the filter form, I get a
>javax.servlet.ServletException: BeanUtils.populate exception, despite
>I am able to display values populated by the action.
>
>It seems that in this case Struts tries to populate a bean of type
>StorableObject, and since this one is abstract it results in a error.
>
>So, my question, is there a way to make struts use a generic form bean
>with any properties names and values and then handle it by hand in the
>action ?
>
>Any input would be appreciated.
>Sylvain.
>
>---------------------------------------------------------------------
>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