PDA

View Full Version : referenceData() not being called on initial display of view


gmazza
Apr 25th, 2006, 08:57 AM
Hello,

I have a simple two-form web app, consisting of a database login form which will then activate a report parameter form. After the user selects desired parameters for the report, he can select "Submit" and have a PDF report returned to his browser.

The login form is working fine but I can't seem to get the referenceData() method from my ParameterFormController to be called on the initial display of the parameter view. (rD() for the PFC holds lookup values that are to populate drop-down lists on the parameter form.) Subsequent displays of the same view--due to validation errors, for example--*will* cause the rD() method to be called, and the form drop-down lists populated. (I confirmed that rD() isn't being called on the initial display of the parameter form by placing a debugging statement within that method.)

One temporary hack I can do is to add the lookup values already in rD() to the onSubmit() of my LoginFormController -- but obviously I'd like to avoid duplicating the code in two different places, as well as not maintain parameter-form specific data in the LFC.

I suspect the problem is with the way I am activating the parameter form. Here is my process:

1.) I have a www.mycompany.com/login.do map directly to the LoginFormController using the SimpleUrlHandlerMapping in my Spring configuration file. No problem here.

2.) Within the onSubmit() of LoginFormController, I forward directly to the parameter.jsp file (using the ResourceBundleViewResolver), adding only a ParameterForm object (which will store the user's choices) to the Model. No PFC.rD() called here, which is my problem.

3.) Within the POST action of the HTML form within the parameter.jsp, I declare an action called "parameter.do" that links directly to parameterFormController within my Spring configuration file just like #1 above. PFC.rD() is properly called here, and the drop-down lists filled if my parameter form is redisplayed due to validation errors.

How do I recode #2 to have the PFC.rD() be called?

Thanks,
Glen

captrespect
Apr 25th, 2006, 09:31 AM
I think you are having the same problem I had. You can either, map the data like you said and send it to the form, redirect or do what I did:

http://forum.springframework.org/showthread.php?t=22493

gmazza
Apr 25th, 2006, 11:24 AM
I think you are having the same problem I had. You can either, map the data like you said and send it to the form, redirect or do what I did:

http://forum.springframework.org/showthread.php?t=22493

Thanks, I think it was the redirect I was looking for (I'm still a newbie, so I didn't know about it):

http://static.springframework.org/spring/docs/1.2.x/reference/mvc.html#d0e9984:

"It is sometimes desireable to issue an HTTP redirect back to the client, before the view is rendered. This is desireable for example when one controller has been called with POSTed data, and the response is actually a delegation to another controller (for example on a successful form submission). In this case, a normal internal forward will mean the other controller will also see the same POST data, which is potentially problematic if it can confuse it with other expected data. Another reason to do a redirect before displaying the result is that this will eliminate the possiblity of the user doing a double submission of form data. The browser will have sent the initial POST, will have seen a redirect back and done a subsequent GET because of that, and thus as far as it is concerned, the current page does not reflect the result of a POST, but rather of a GET, so there is no way the user can accidentally re-POST the same data by doing a refresh. The refresh would just force a GET of the result page, not a resend of the initial POST data."

Did you have a problem with using a redirect that caused you to need to subclass InternalResourceView, or just felt that was neater than using a redirect? I'll use your approach if the redirect doesn't work for me.

Thanks,
Glen

captrespect
Apr 25th, 2006, 01:24 PM
I was thinking response.redirect(), and I didn't want to code a bunch of urls into my controller. I didn't know about the RedirectView, I'll have to start using that. My approach doesn't have the benifit of eliminating the re-POST.