You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thorbjørn Ravn Andersen <tr...@biobase.dk> on 2003/07/24 15:12:29 UTC

Struts + Hibernate: A few newbie questions about how to get this right?

I have spent quite some time working with creating a new web interface 
on top of an existing database.  As we want to eventually change the 
schema we have decided to put an abstraction layer on top of it, which I 
am in the process of modelling as Hibernate beans, where Ihave just 
started dealing with the process of updating information in these 
persisted beans (previously was read-only), and presenting them with 
bean:* and the display taglib.

I have previously written a search interface accessing the database 
directly (due to some very complicated where-clauses) using Struts in 
order to gather the user preferences for refining the search, which has 
worked well for quite a while.  So I am familiar with the basic concept 
of using a form bean to store the information, and Struts taglibs for 
creating web-forms to alter this information.

Now I want to edit my persistent beans (containing multi-level 
master-detail information) with a Struts-based interface, and in order 
to avoid spending time reinventing the wheel, I would like to ask the 
community first:

* Can I use a persistant bean as my FormBean (or would that be asking 
for inconsistencies), or should I work with a DynaBean and then copy the 
result to the persistant bean in the end?  I will probably need some 
validation.

* If not, is there an easy way to populate such a DynaBean from my 
persistant bean and vice versa?  I would rather not have to write a lot 
of setXX( getXX()) statements.

* I have understood from the struts-hibernate example by Ted Husted that 
Struts can utilize Hibernate as a plugin, but I did not understand what 
this implies.  Is there a ressource that explains this?  Is there any 
benefit from just using the two packages directly?

Any insight would be appreciated :)  Thanks in advance.


-- 
  Thorbjoern Ravn Andersen     Scandiatransplant
                               Skejby Sygehus, indgang 3
  +45 89 49 53 01              DK-8200 AArhus N
  http://biobase.dk/~tra         



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


Re: Struts + Hibernate: A few newbie questions about how to get this right?

Posted by Vilya Harvey <vi...@digitalsteps.com>.
Thorbjørn Ravn Andersen wrote:
> * Can I use a persistant bean as my FormBean (or would that be asking 
> for inconsistencies), or should I work with a DynaBean and then copy the 
> result to the persistant bean in the end?  I will probably need some 
> validation.

You could, I believe, but AFAIK it's not recommended. The Struts form beans 
are really part of the view layer and should be kept separate from the 
business and persistence layers where possible. A better approach is to use 
a DynaBean for collecting the form data and have the actions copy it into 
the appropriate model class.

> * If not, is there an easy way to populate such a DynaBean from my 
> persistant bean and vice versa?  I would rather not have to write a lot 
> of setXX( getXX()) statements.

Have a look at the commons-beanutils package that comes with Struts. In 
particular, you'll probably find BeanUtils.copyProperties() quite helpful.

Hope that helps,
Vil.
-- 
Vilya Harvey
vilya.harvey@digitalsteps.com                 / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457                 http://www.digitalsteps.com/

--Disclaimer--

This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this email and you are not a named
addressee, please inform the sender at Digital Steps Ltd by phone on
+44 (0)1483 469 480 or by reply email and then delete the email from
your system. If you are not a named addressee you must not use,
disclose, distribute, copy, print or rely on this email. Although
Digital Steps Ltd routinely screens for viruses, addressees should
check this email and any attachments for viruses. Digital Steps Ltd
makes no representation or warranty as to the absence of viruses in this
email or any attachments.