Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • multiple instances of one ActionForm

    7 answers - 931 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.1 | | 1191 bytes | |

    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.

    8/8/05, Leo Asanov <leonidasanov (AT) yahoo (DOT) comwrote:
    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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.2 | | 1374 bytes | |

    8/8/05, Leo Asanov <leonidasanov (AT) yahoo (DOT) comwrote:
    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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.3 | | 1262 bytes | |

    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.
  • No.4 | | 1411 bytes | |

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

    Michael.

    8/9/05, Leo Asanov <leonidasanov (AT) yahoo (DOT) comwrote:
    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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.5 | | 1240 bytes | |

    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.ERRR_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 True ActionForm per se, the rest you will have to deal
    with manually.
  • No.6 | | 1045 bytes | |

    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

    8/10/05, Leo Asanov <leonidasanov (AT) yahoo (DOT) comwrote:
    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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org
  • No.7 | | 1058 bytes | |

    8/10/05, Leo Asanov <leonidasanov (AT) yahoo (DOT) comwrote:
    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.

    , 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 (AT) struts (DOT) apache.org
    For additional commands, e-mail: user-help (AT) struts (DOT) apache.org

Re: multiple instances of one ActionForm


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "Java"

EMSDN.COM