File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass data from onSubmit to referenceData?

 
Jehan Jaleel
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ken Krebs
Ranch Hand
Posts: 451
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic