You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Ke...@cgu.com.au on 2001/05/23 02:18:13 UTC

What is the best way to have one jsp mapping to two forms?

This e-mail is subject to the disclaimer contained at the bottom
of this message.  This e-mail message has been scanned for Viruses 
and Content and cleared by MailMarshal.
I have two actionForms one for person information 'personForm' and one for
address 'addressForm'. I would like to have one JSP page to provide input
form for both person information and address information. Currently one JSP
and one ActionForm is easy to implement in Struts. But I am not sure what
is the best implementation or options for one JSP page with two
ActionForms.

Any tips?

Regards
Kelvin


The informatuon transmitted in this message and attachments (if any)
is intended only for the person or entity to which it is addressed.  
The message may contain confidential and/or privileged material.  
Any review, retransmission, dissemination or other use of or taking 
of any action in reliance upon this information by persons or entities
other than the intended recipient is prohibited.  

If you received this in error, please contact the sender and delete the
material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or
distribute the information contained in this e-mail and any attached files
with the permission of CGU Insurance.

Re: What is the best way to have one jsp mapping to two forms?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
(Stripping all the disclaimer mumbo jumbo that's longer than the message
:-)

On Wed, 23 May 2001 Kelvin_Ho@cgu.com.au wrote:

> 
> I have two actionForms one for person information 'personForm' and one for
> address 'addressForm'. I would like to have one JSP page to provide input
> form for both person information and address information. Currently one JSP
> and one ActionForm is easy to implement in Struts. But I am not sure what
> is the best implementation or options for one JSP page with two
> ActionForms.
> 

If the information is actually in separate forms, the simplest thing to do
is have them submit to separate actions that both declare the same page as
their "inputForm".  You'll probably need to keep the associated beans in
session scope so that the person information (for example) gets
redisplayed correctly when the address information's form bean returns a
validation error.

If the information is all in one form, but you really want to update two
different beans, Struts only helps you automatically with part of that.  A
couple of options to consider:

- Create a "combined" form bean that delegates its updates to the
  actual person and address beans underneath

- In your action, use the BeanUtils.populate() method (which is what
  Struts uses internally for automatic form bean population) yourself
  to populate the "other" bean.

> Any tips?
> 
> Regards
> Kelvin
> 

Craig