• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to pass data from onSubmit to referenceData?

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have some data that I want to pass from the onSubmit method of my MVC Controller (extends SimpleFormController) to the referenceData method of that controller. How can I go about doing this?


It is not as simple as putting it as a request attribute because when the code comes to the referenceData a new request is created.

If you are wondering why I need to do this, it is for pagination. In the referenceData method is where I get the default list of rows from the db. But once the user pages I do a form submit on my JSP and get the next page in my onSubmit. The problem now is that when the code comes back to the referenceData after that submit it is overwritting the "paged" list with the original list.


Thanks in advance for any help.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The referenceData method is called by the framework before your onSubmit method is called, not after.

The workfow is well documented in the Javadoc for AbstractFormController.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am doing is that I am doing a form submit to the same Controller so it should call the onSubmit first. I debugged the code and as I stepped through it I saw that onSubmit was being called first.

Any other suggestions. Thanks again.
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that referenceData() is of any help to you here. If you look at the javadoc, it is called before the initial rendering of the View before the form is submitted. Generally, this is your opportunity to put things in the Model (request attributes) that your form needs when it is rendered before it is submitted. If you want to pass something to another Controller, you can put it in the Model or if you're redirecting to the other Controller you can put it in the session.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if your JSP had a list of data (like a summary screen), in which method would you populate this list? (sounds like a good interview question)
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I figured out the solution to this and it was quiet simple.

Before in my onSubmit method I was creating a new ModelView and doing a redirect to my successview (that is why I was losing the request)...



But now I just did the following...


This fixed it. Now I have my request parameters in my referenceData method and I get the correct data for each page.

Thanks all for any help.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic