You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ted Husted <hu...@apache.org> on 2001/12/05 13:44:18 UTC

Re: Business objects as ActionForms

This really only works if all your properties are Strings or booleans.
Binary types can't be transmitted by HTTP, and so can't be represented
to the user for correction. The ActionForm is a *buffer* to be used by
the HTML tags. Once the data is validated, it can be converted and
transferred to your application's JavaBeans. 

We tried making the ActionForm an interface in the first place, but, in
practice, there were simply too many side effects. 

http://www.mail-archive.com/struts-dev%40jakarta.apache.org/msg03590.html

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg08070.html

If your JavaBean only uses String and boolean properties, and doesn't
make immediate state changes to your model, you can nest it and use the
dotted syntax. Otherwise, it's a wild goose chase.


Yunming.Li@fisonline.com wrote:
> 
> use nested class in your form: just put Product as a member of your form
> bean like this:
> 
>    private Product product = new Product();
> 
>    public Product getProduct() {
>        return product;
>    }
> 
>    public void setProduct(Product p)
>    {
>         this.product = p;
>    }
> 
> then if your jsp page has:
> <html:text property="product.price"/>
> it will call your Product's get and set method automatically.
> 
> Yunming
> 
> -----Original Message-----
> From: Scriven, Marcos [mailto:Marcos.Scriven@gs.com]
> Sent: Thursday, November 08, 2001 8:40 AM
> To: 'Struts Users Mailing List'
> Subject: Business objects as ActionForms
> 
> Hi
> 
> I have some fairly simple objects in my business logic, but with many
> attributes, that are really just containers. For instance, I have a Product
> class, with gets/sets like getPrice/setPrice. It has about twenty other
> attributes.
> 
> When I come to having a form for adding a new product (or editing), I have
> to then effectively repeat this object, just for the sake of having a
> validate method. I could hold an instance of Product in AddProduct form, but
> then I would still have to add the set methods.
> 
> Is there a way for me to implement some kind of ActionForm interface, which
> would then allow me to both extend my Product object, and implement the
> ActionForm interface to add a validate method.
> 
> If this is bad design, can anyone suggest a better way to avoid duplicating
> simple business classes with form beans?
> 
> Thanks
> 
> Marcos
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>