You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Gallagher, Jim (RBoS ITD&S Dublin)" <Ji...@rbs.co.uk> on 2006/11/22 15:11:56 UTC

Very basic question on formbeans

Hi,

	I've designed & written a couple of struts applications up to now,
and recently the solution to a problem has caused me to wonder if I'm making
a fundamental error in the way I've been doing it. 

	Up to now, when designing a jsp I've only used the formbean to
collect the information entered, rather than to pass it to the jsp in the
first place. I'm wondering whether it's a better idea to create the
formbean, populate it and use that to pass the information to the jsp? I can
see there might be some MVC benefits, but I'd be interested in other
peoples' opinions.

	Apologies if this is blindingly obvious, but I'm keen to determine
the best way of utilising struts.


                                 Regards,

                                         Jim

Jim Gallagher,
New BACS Team,
Domestic Payments,
Payments, Security & Fraud,
Royal Bank of Scotland,
Parkgate Business Park,
Parkgate Street,
Dublin 8.
RBS Depot Code: DUB

ITS: 			7-4171-7167
External:		+353-1-648 7167 
Internet mail: 	jim.gallagher@rbs.co.uk



The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB

Authorised and regulated by the Financial Services Authority.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.


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


Re: Very basic question on formbeans

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jim,

Gallagher, Jim (RBoS ITD&S Dublin) wrote:
> I'm wondering whether it's a better idea to create the
> formbean, populate it and use that to pass the information to the jsp?

This really is the "struts way". But, in order to do this, you don't
have to do a ton of work. For instance, simply modify your
struts-config.xml action mappings to include the "name" attribute for
the mapping which initially displays your (empty) form. That will set up
the (empty) form bean for further use.

You can do nothing at this point, and you'll get an empty form, just
like you do, now. Or, you can add code to your action (if you are using
one) or to your JSP (though I highly recommend using an action instead
of putting code in your JSP) that grabs the form bean just like in your
form handling actions.

Once you have a reference to this form bean, you can fill it with data.
A simple example is loading a record from a DB for editing:

1. Hit the /edit.do URI which has "myForm" as the form bean.

2. Fetch the appropriate record from the database.

3. EditAction takes its "form" parameter and casts it to the appropriate
   type (MyBeanType).

4. Fill the bean with data from the DB record (don't forget to include
   the records PK).

5. Display your form, remembering to include all the data you just
   stuck into the bean, instead of just leaving the fields blank.

~~~~~

6. Post your form to your form handler (/save.do).
   If you use struts validation, it can check to make sure that your
   form fields are (at least mostly) valid and redisplay the form
   if there's a problem. This is a huge advantage that I recommend
   you .. umm, take advantage of.

7. Process your form normally.

Hope that helps,
- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFZF2S9CaO5/Lv0PARAgjjAJ9dJ4r+PUlvkJ2w7360w1weOASzEgCdEVFj
/hpfA2psUPbscPSoY5ZfwtQ=
=csK4
-----END PGP SIGNATURE-----

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


Re: Very basic question on formbeans

Posted by Albert L Sapp <as...@uiuc.edu>.
Jim,

Basically, that is how our application is set up.  There are transfer 
object beans that handle the movement between our controller layer and 
model and form beans for moving data between the view and controller 
layer.  Sometimes, the TO and form bean may be exact matches and other 
times I may have additional fields of computed data that is needed in 
the form bean.

Just my 2 cents.

Al

Gallagher, Jim (RBoS ITD&S Dublin) wrote:
> Hi,
>
> 	I've designed & written a couple of struts applications up to now,
> and recently the solution to a problem has caused me to wonder if I'm making
> a fundamental error in the way I've been doing it. 
>
> 	Up to now, when designing a jsp I've only used the formbean to
> collect the information entered, rather than to pass it to the jsp in the
> first place. I'm wondering whether it's a better idea to create the
> formbean, populate it and use that to pass the information to the jsp? I can
> see there might be some MVC benefits, but I'd be interested in other
> peoples' opinions.
>
> 	Apologies if this is blindingly obvious, but I'm keen to determine
> the best way of utilising struts.
>
>
>                                  Regards,
>
>                                          Jim
>
> Jim Gallagher,
> New BACS Team,
> Domestic Payments,
> Payments, Security & Fraud,
> Royal Bank of Scotland,
> Parkgate Business Park,
> Parkgate Street,
> Dublin 8.
> RBS Depot Code: DUB
>
> ITS: 			7-4171-7167
> External:		+353-1-648 7167 
> Internet mail: 	jim.gallagher@rbs.co.uk
>
>
>
> The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
>
> Authorised and regulated by the Financial Services Authority.
>
> This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent.
>
> Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate.
>
>
> ---------------------------------------------------------------------
> 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