You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Leo Asanov <le...@yahoo.com> on 2005/08/09 04:13:58 UTC

multiple instances of one ActionForm

Hi!

Is there any standard ways to manage multiple
instances of one form with Struts? I have application
which is supposed to take theorerically unlimited
number of person's descriptions. Every time user
clicks "add one more person" he/she gets exactly the
same form (with the same validation rules) to fill. At
the end user clicks "finish" and all data is saved.
I'm sure this is quite common task. So far I can't see
any mechanism in Struts supporting multiple instances.
And if I manage instances manually in Action class I
loose some built-in functionality, like forms
prepopulation. Any hints/ideas?

Cheers,
Leo


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

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


Re: multiple instances of one ActionForm

Posted by Leo Asanov <le...@yahoo.com>.

--- Michael Jouravlev <jm...@gmail.com> wrote:

> Do you need it?

Yes.

> Back/Forward navigates between resources. Resource
> is an Action, not a
> JSP nor an ActionForm. So, to use default
> Back/Forward functionality
> you need to define as many action mappings as you
> have "navigatiable"
> pages. For each action mapping you can have own
> actionform.

Sounds good, but Struts controller takes action
mappings from the configuration xml file. You can't
create your own action mapping programmatically and
let controller to be aware of that, could you?

Cheers,
Leo

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: multiple instances of one ActionForm

Posted by Michael Jouravlev <jm...@gmail.com>.
On 8/10/05, Leo Asanov <le...@yahoo.com> wrote:
> That's the first thing I thought of. But in that case
> you loose "Back" function (and maybe something else as
> well).

Do you need it?

> You could do something if user presses "back"
> on the page, but you can't do much if he clicks "back"
> in the browser unless you write your own request
> handler.

Back/Forward navigates between resources. Resource is an Action, not a
JSP nor an ActionForm. So, to use default Back/Forward functionality
you need to define as many action mappings as you have "navigatiable"
pages. For each action mapping you can have own actionform.

Or, conversely, you can serve all content from one action, in this
case you can prevent a user to use Back button at all, if you use
redirection and all your GET requests are the same.

Michael.

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


Re: multiple instances of one ActionForm

Posted by Leo Asanov <le...@yahoo.com>.
That's the first thing I thought of. But in that case
you loose "Back" function (and maybe something else as
well). You could do something if user presses "back"
on the page, but you can't do much if he clicks "back"
in the browser unless you write your own request
handler. And I am trying to avoid that as it makes
things much more complicated and prone to errors.

Cheers,
Leo

--- Jeff Beal <jb...@gmail.com> wrote:

> Could you just put all of your completed ActionForms
> in a
> session-scoped collection, then loop through that
> collection when the
> user clicks "Finish"?  This isn't a standard
> procedure, to my
> knowledge, but it would be the first approach I
> would take given
> similar requirements.
> 
> -- Jeff


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: multiple instances of one ActionForm

Posted by Jeff Beal <jb...@gmail.com>.
Could you just put all of your completed ActionForms in a
session-scoped collection, then loop through that collection when the
user clicks "Finish"?  This isn't a standard procedure, to my
knowledge, but it would be the first approach I would take given
similar requirements.

-- Jeff

On 8/10/05, Leo Asanov <le...@yahoo.com> wrote:
> Yes, I am talking about one form per request
> situation. I don't really see how I can use it as it
> is. ActionForm object will be overriden with the
> latest one and all previous data will be lost.
> 
> Ideally I would prefer to have all data stored in the
> session automatically and only when user clicks
> "finish" I would take all ActionForm objects from the
> session and save them into database. Without multiple
> instances of one form it can easily be done.
> 
> Cheers,
> Leo
>

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


Re: multiple instances of one ActionForm

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
You may lose *automatic* validation... remember that there is no technical
reason you have to use ActionForms at all, and if you do use them there is
nothing that says you have to associate them with Action Mappings.

For instance, I have seen some situations where developers didn't want the
auto-population to occur for one reason or another, and this is something
that cannot currently be disabled.  So, they wound up doing something like
this in their Actions:

MyActionForm af = new MyActionForm();
RequestUtils.populate(af, request);
ActionErrors errors = af.validate();
if (errors != null && !errors.isEmpty()) {
  request.setAttribute(Globals.ERROR_KEY, errors);
  return mapping.findForward("validationFailed");
}

You could do the same if you wanted multiple ActionForms per page... you
can instantiate as many as you want and deal with them manually like this.

The only "catch" is that the taglibs expect a single ActionForm per page
that is under a specific key in request.  There is nothing to stop you
from putting other ActionForms in request under different keys, but only
one can be The One True ActionForm per se, the rest you will have to deal
with manually.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Wed, August 10, 2005 3:28 am, Leo Asanov said:
>
> Michael, I don't think I really understand your
> suggestion. Don't I loose struts validation
> functionality if I don't have an ActionForm per html
> form?
>
> Cheers,
> Leo
>
>> ActionForm does not have to correlate to HTML form
>> one-to-one. You can
>> create one ActionForm with session scope and use
>> nested DTOs/BOs for
>> each HTML form. For relatives' form you can use a
>> list of nested DTOs.
>> It is even simpler that you do not need to render a
>> particular
>> relative, you just enter them.
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> 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


Re: multiple instances of one ActionForm

Posted by Leo Asanov <le...@yahoo.com>.
Michael, I don't think I really understand your
suggestion. Don't I loose struts validation
functionality if I don't have an ActionForm per html
form?

Cheers,
Leo

> ActionForm does not have to correlate to HTML form
> one-to-one. You can
> create one ActionForm with session scope and use
> nested DTOs/BOs for
> each HTML form. For relatives' form you can use a
> list of nested DTOs.
> It is even simpler that you do not need to render a
> particular
> relative, you just enter them.



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: multiple instances of one ActionForm

Posted by Michael Jouravlev <jm...@gmail.com>.
ActionForm does not have to correlate to HTML form one-to-one. You can
create one ActionForm with session scope and use nested DTOs/BOs for
each HTML form. For relatives' form you can use a list of nested DTOs.
It is even simpler that you do not need to render a particular
relative, you just enter them.

Michael.

On 8/9/05, Leo Asanov <le...@yahoo.com> wrote:
> Yes, I am talking about one form per request
> situation. I don't really see how I can use it as it
> is. ActionForm object will be overriden with the
> latest one and all previous data will be lost.
> 
> Ideally I would prefer to have all data stored in the
> session automatically and only when user clicks
> "finish" I would take all ActionForm objects from the
> session and save them into database. Without multiple
> instances of one form it can easily be done.
> 
> Cheers,
> Leo
> 
> > If you just want to have your 'add one more person'
> > button display a page
> > with a form to enter that person's details (i.e.
> > multiple instances of the
> > same form being used one per request) you don't need
> > to do anything special
> > besides make sure your form bean implements reset()
> > appropriately.

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


Re: multiple instances of one ActionForm

Posted by Leo Asanov <le...@yahoo.com>.
Yes, I am talking about one form per request
situation. I don't really see how I can use it as it
is. ActionForm object will be overriden with the
latest one and all previous data will be lost. 

Ideally I would prefer to have all data stored in the
session automatically and only when user clicks
"finish" I would take all ActionForm objects from the
session and save them into database. Without multiple
instances of one form it can easily be done.

Cheers,
Leo

> If you just want to have your 'add one more person'
> button display a page 
> with a form to enter that person's details (i.e.
> multiple instances of the 
> same form being used one per request) you don't need
> to do anything special 
> besides make sure your form bean implements reset()
> appropriately.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: multiple instances of one ActionForm

Posted by Laurie Harper <la...@holoweb.net>.
Leo Asanov wrote:
> Is there any standard ways to manage multiple
> instances of one form with Struts? I have application
> which is supposed to take theorerically unlimited
> number of person's descriptions. Every time user
> clicks "add one more person" he/she gets exactly the
> same form (with the same validation rules) to fill. At
> the end user clicks "finish" and all data is saved.
> I'm sure this is quite common task. So far I can't see
> any mechanism in Struts supporting multiple instances.
> And if I manage instances manually in Action class I
> loose some built-in functionality, like forms
> prepopulation. Any hints/ideas?

Do you mean multiple instances of the same form on the same page? If so you 
can use a single form with all the people's details. If you use nested 
properties in your form bean you can easily keep each person's data 
separated out.

If you just want to have your 'add one more person' button display a page 
with a form to enter that person's details (i.e. multiple instances of the 
same form being used one per request) you don't need to do anything special 
besides make sure your form bean implements reset() appropriately.

L.
-- 
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/laurie


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


Re: multiple instances of one ActionForm

Posted by Michael Jouravlev <jm...@gmail.com>.
On 8/8/05, Leo Asanov <le...@yahoo.com> wrote:
> Michael,
> 
> I don't see the analogy with "Save As" dialog. And
> ActionForm is not a businees object indeed. Don't know
> what to do with this valuable information though...
> 
> If there is nothing in Struts which can help me then
> it is the information I am looking for.
> Although I would appreciate any ideas on application
> design for my case. Lets consider a simple example -
> multi-formed survey.
> Form 1: Person's details
> Form 2: Person's address details
> Form 3: Is there any relatives?
> Form 4: Relative's details
> Form 5: Is there any more relatives?
> If "yes" - go to Form 4.
> ....
> Form 6: Some other details
> Form 7: Finish a survey
> 
> What options do I have? I could manually process forms
> in Form4 Action class and save instances in session,
> for example, but then "Back" wouldn't work as
> expected.

I see. I misunderstood you. 

Why do you think you need multiple action forms? You can use one
action form with session scope, and nested beans for each html form.
For relatives' details you would have arraylist or a map.

Michael.

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


Re: multiple instances of one ActionForm

Posted by Leo Asanov <le...@yahoo.com>.
Michael, 

I don't see the analogy with "Save As" dialog. And
ActionForm is not a businees object indeed. Don't know
what to do with this valuable information though...

If there is nothing in Struts which can help me then
it is the information I am looking for. 
Although I would appreciate any ideas on application
design for my case. Lets consider a simple example -
multi-formed survey.
Form 1: Person's details
Form 2: Person's address details
Form 3: Is there any relatives?
Form 4: Relative's details
Form 5: Is there any more relatives?
If "yes" - go to Form 4.
....
Form 6: Some other details
Form 7: Finish a survey

What options do I have? I could manually process forms
in Form4 Action class and save instances in session,
for example, but then "Back" wouldn't work as
expected.   

I am not talking about processing or manipulating the
data, this's purely interface issue at this point of
time.

Cheers,
Leo

--- Michael Jouravlev <jm...@gmail.com> wrote:

> If you need to save document from Microsoft Word,
> you open "File Save"
> dialog. When you need to save another file, do you
> create another
> "File Save" dialog? Do all these dialogs remain
> allocated until you
> shut down the system?
> 
> ActionForm is not a business object.
> 
> Michael.
> 
> On 8/8/05, Leo Asanov <le...@yahoo.com>
> wrote:
> > Hi!
> > 
> > Is there any standard ways to manage multiple
> > instances of one form with Struts? I have
> application
> > which is supposed to take theorerically unlimited
> > number of person's descriptions. Every time user
> > clicks "add one more person" he/she gets exactly
> the
> > same form (with the same validation rules) to
> fill. At
> > the end user clicks "finish" and all data is
> saved.
> > I'm sure this is quite common task. So far I can't
> see
> > any mechanism in Struts supporting multiple
> instances.
> > And if I manage instances manually in Action class
> I
> > loose some built-in functionality, like forms
> > prepopulation. Any hints/ideas?
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: multiple instances of one ActionForm

Posted by Michael Jouravlev <jm...@gmail.com>.
If you need to save document from Microsoft Word, you open "File Save"
dialog. When you need to save another file, do you create another
"File Save" dialog? Do all these dialogs remain allocated until you
shut down the system?

ActionForm is not a business object.

Michael.

On 8/8/05, Leo Asanov <le...@yahoo.com> wrote:
> Hi!
> 
> Is there any standard ways to manage multiple
> instances of one form with Struts? I have application
> which is supposed to take theorerically unlimited
> number of person's descriptions. Every time user
> clicks "add one more person" he/she gets exactly the
> same form (with the same validation rules) to fill. At
> the end user clicks "finish" and all data is saved.
> I'm sure this is quite common task. So far I can't see
> any mechanism in Struts supporting multiple instances.
> And if I manage instances manually in Action class I
> loose some built-in functionality, like forms
> prepopulation. Any hints/ideas?

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