Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: formBackingObject called twice

  1. #1
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default formBackingObject called twice

    Hi,

    I am extending the AbstractWizardFormController and am running into the problem of the (overridden) formBackingObject method being called more than once in a wizard style form sequence. This leads to loss of data between POST requests.

    When I remove the formBackingObject implementation from my controller class the BaseCommandController.createCommand is executed twice in the form sequence leading to the same problem.

    I tried setting setSessionForm(true) in my controller, without effect.

    I am relying on Spring's build in support for setting the target page for page changes by specifying _target1, _target2 request parameters in my jsp's like this:

    Code:
    <input class="button" name="_target1" type="submit" value="<fmt&#58;message key="addGallery.next" />">
    
    <input class="button" name="_cancel" type="submit" value="<fmt&#58;message key="addGallery.cancel" />">
    etc.

    The problem first appeared when using this mechanism. Before, when relying on a implementation of the getTargetPage method, the problem did not occur.

    From other posts I concluded I should not override the getTargetPage method when relying on this mechanism, correct?

    I can provide code samples and debug level output if needed.

    Thanks for your help.

    -- Thomas







  2. #2
    Join Date
    Nov 2004
    Posts
    2

    Default formBackingObject called twice

    Same problem here,

    The session form attribute seems to be getting lost on submitting the second page of our wizard. Thus handleRequestInternal calls handleInvalidSubmit which returns us to the first page of the wizard with a new command object.

    Any help would be appreciated.

  3. #3
    Join Date
    Nov 2004
    Location
    Rural Ireland
    Posts
    36

    Default

    Just to let people know that we've found a way around this (I'm working with paudi). We have to specifically set the session attribute in the wizard controller for the second page (i.e. in our referenceData() method, we have a
    Code:
    session.setAttribute&#40;this.class.getName&#40;&#41;.form.<data holder name>, <object name>
    line that sets the attribute in the session. We were just under the impression that this should be done automatically by spring.

  4. #4
    Join Date
    Nov 2004
    Posts
    159

    Default

    Hi,

    I'm basically NOT a GUI person but trying to develop a prototype and ended up the GUI using JSP, Spring MVC for that. I'm some experience with Struts.

    This question is not related to this post but as i see you guys using JSP/Spring MVC, i thought that i would post my question here.

    In my application, i've two objects Project and Resource which have many-to-many relationship. I've a Form for Project and another for Resource and if i try to add Project and resource, they work nicely. But in reality, i would like to add Resources to the Project. Hence i added a button caled "Add Project to Resource". This link takes me to the Resource edit form. The problem is that, i would like a way to tell the Resource form that i'm adding Resource to THIS Project so that it can add an entry in the association table called "ProjectResource".

    So, how will i indicate the Resource form that i'm adding a resource to THIS project. My idea is that we can save the Project as session attribute using

    Code:
    request.getSession&#40;&#41;.setAttribute&#40;"Project", project&#41;;
    and retrieve the same attribute later. But i'm not clear exactly where should i put this code? I've the ProjectController and ProjectFormController class for Project form and similar ones for Resource. When the user clicks the "Add Resource to Project" button, could someone please let me know, how and where should i set this attribute? or is there any other better approach.


    If someone could point me to any references/samples, i can read it.


    I greatly appreciate any input on this.


    Thanks!

  5. #5
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    I solved it with the following formBackingObject implementation:

    Code:
     protected Object formBackingObject&#40;HttpServletRequest request&#41; throws Exception &#123;
            Object command = null;
    
                try &#123;
                    command = this.getCommand&#40;request&#41;;
                &#125; catch &#40;Exception e&#41; &#123;
                    logger.info&#40;"formBackingObject&#58; exception thrown " + e.getMessage&#40;&#41;&#41;;
                &#125;
            &#125;
            if &#40;command == null&#41; &#123;
                request.getSession&#40;true&#41;;
                command = new Object&#40;&#41;;
            &#125;
            WebUtils.setSessionAttribute&#40;request, getFormSessionAttributeName&#40;&#41;, command&#41;;
            return command;
        &#125;
    Looking at the getCommand() implementation in the AbstractFormController leds me to believe that it is intentional that adding the command object to the session between form submissions should be done manually, but maybe I am still missing out on some essentials.

  6. #6
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    Of course "Object" in
    Code:
    Object command = null;
    should be substituted with the Type of your command object, as it can be retrieved by the getCommandClass() method.

  7. #7
    Join Date
    Nov 2004
    Posts
    159

    Default

    Thanks very much delnoij for the code sample.

    I'll try this out. Per my understanding, i need to set the 'Project' object in my session attribute in the ProjectFormController (is it onSubmit?). Is that correct?

    Thanks again!

  8. #8
    Join Date
    Nov 2004
    Posts
    159

    Default

    Thanks very much delnoij.

    I implemented this based on your idea and it works great!

    Thanks a lot!

  9. #9
    Join Date
    Nov 2004
    Posts
    159

    Default

    In my Project Form, i would like to list all the "Resources", if any. Could you please point me to some references on how should i do that in JSP? (I'm looking for a drop-down menu). As i mentioned, i'm NOT a GUI person but can pick up things fast if someone can point out to references.

    Thanks a lot!

  10. #10
    Join Date
    Nov 2004
    Posts
    159

    Default

    In my ProjectDAO/Manager, i've a method that returns a set of "Resources".

Similar Threads

  1. Replies: 2
    Last Post: Sep 9th, 2005, 07:33 AM
  2. Replies: 8
    Last Post: Aug 31st, 2005, 11:38 AM
  3. onSubmit not called
    By christophe in forum Web
    Replies: 4
    Last Post: Jul 29th, 2005, 05:10 PM
  4. Replies: 2
    Last Post: Jul 5th, 2005, 02:20 AM
  5. indirectly called method not intercepted
    By springtester in forum AOP
    Replies: 1
    Last Post: Sep 1st, 2004, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •