You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sagar Naik <sa...@yahoo.co.in> on 2005/07/10 08:40:32 UTC

Preload FormBean

Hi
Struts has got the ability to 
get the data on the form into a bean
Is the reverse possible ?
Scenario is
I have to edit some data in the form.
So I have to load the text fields in the form with
some data values from a Database Table Record.
Can I do tht initializing the bean object and give it
to struts to display the values ?


(pl note tht I m aware of the solution tht
 One can store the bean as a session attribute and
 use it in the page to get the properties of the bean
object)

Thanks


		
_______________________________________________________
Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://in.mail.yahoo.com

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


Re: Preload FormBean

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Sagar Naik" <sa...@yahoo.co.in>

> I have to edit some data in the form.
> So I have to load the text fields in the form with
> some data values from a Database Table Record.
> Can I do tht initializing the bean object and give it
> to struts to display the values ?

Yes, though the answer comes from BeanUtils, not Struts itself.  In your 
Action, before the JSP is displayed, (after you retrieve the bean with the 
database values,) you can call
   BeanUtils.copyProperties( destination, origin );
to copy the values over.  If the property names match, and both objects 
conform to the JavaBeans spec (mostly for naming the get/set methods) then 
it will just work.  If not, you may have to give BeanUtils some hints about 
what you want it to do.

If you search the archives for 'propulate form bean' you should find some 
good info.  Also take a look at the mailreader-example app (in the 'webapps' 
directory of the 1.2.7 distribution) which has an example of pre-populating 
the form bean in EditRegistrationAction.

-- 
Wendy Smoak




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