Issue Details (XML | Word | Printable)

Key: SPR-3656
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Sayeed Nusrulla Sami
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

AbstractWizardFormController views do not send current page number by default

Created: 04/Jul/07 10:31 PM   Updated: 29/Feb/08 05:03 AM
Component/s: SpringWEB
Affects Version/s: 2.0.6
Fix Version/s: 3.0 M1

Time Tracking:
Not Specified

Environment: Windows XP SP2, RHEL4.0 , Bea Weblogic 9.2,
Issue Links:
Related

Virtual Machine: BEA JRockit JVM - 5.0
Platform: BEA WebLogic - 9.0


 Description  « Hide
Hi, There seem to be a bug in the AWFC, I have logged this in the forum, but I didnt get any replies.

I have been using AbstractWizardFormController, it works fine during the normal flow of execution.

Scenario:

the AWFC has three pages.
page1, page2, page3.
All of the pages have some validations to be done.

   1. the user issues a get request to the AWFC and the first page is displayed
   2. The user submits the page1, the target is the page2. everything works fine till now, the user is shown the page2
   3. The user now refreshes, for some reasons the page2 gets validated , which must not happen. becuase the user has refreshed the post request of the page1.

Looking into the code of the AbstractWizardFormController in the processFormSubmission(...) method, line number 494 (spring 2.0.6) there is a check that happens.
Code:

// Normal submit: validate current page and show specified target page.
if (!suppressValidation(request, command, errors)) {
if (logger.isDebugEnabled()) {
logger.debug("Validating wizard page " + currentPage + " for form bean '" + getCommandName() + "'");
}
validatePage(command, errors, currentPage, false);
}

.

which should be there incase of normal flow of the AWFC.
but since the page1 was validated and the page2 was shown, because of this there is call to the showPage(request, errors, targetPage) at line number 513.
as a result a session attribute is set in the showPage method at line number request.getSession().setAttribute(pageAttrName, pageInteger); 341.

Now back to the scenario.

page1 is submitted, the targetPage is 1 as a result the session has the attribute pageAttrName as 1. the page2 is shown as a result of the page1 submission which is normal.

now when the user refreshes the page2(resubmits the page1 post request). the validatePage is called from the processFormSubmission and the page2 gets validated which shouldnot happen,

Iam assuming that the fix to this would be to add an additional check in the if construct of the AWFC line 494,

Code:

// Normal submit: validate current page and show specified target page.
// determine the targetPage by calling the getTargetPage() method and add the following .
if (targetPage != currentPage && !suppressValidation(request, command, errors)) {
if (logger.isDebugEnabled()) {
logger.debug("Validating wizard page " + currentPage + " for form bean '" + getCommandName() + "'");
}
validatePage(command, errors, currentPage, false);
}

.

This should handle the refreshes without calling validate.
Kindly let me know if this is correct.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 26/Jul/07 08:08 AM
The problem here is that submissions to the same page are allowed: Forms may be designed to allow an "Accept" style button that takes the submission, validates it, and then shows the same page again. We do have to validate in this case.

The solution for your scenario is to explicitly specify the "_page" parameter (see PARAM_PAGE in the javadoc) on each of your pages, typically as a hidden form field, indicating the submitting page. With this in place, a browser refresh or usage of the back button will still result in correct submission behavior. Please give this a try...

Juergen

Sayeed Nusrulla Sami added a comment - 29/Jul/07 11:19 PM
Hi Juergen,

Thanks for the suggestion, it worked like a charm,

But I have some comments,
Since majority of the forms are sequential and they dont submit to themselves like (the "Accept" style),
wouldnt it be nice if the AWFC handled the resubmit problem by default, rather than the using _page attribute.

I was thinking that a property for using the accept style in the AWFC would have been good,
by default the property is false and whenever somebody needs to design such form they can turn it on.

An extra condition which considers the value of the accept button to call the validatePage would do the trick,

Thanks & Regards
Sami

Juergen Hoeller added a comment - 30/Jul/07 03:14 AM
Good point: We could turn this into the default behavior. However, the problem here is that AbstractWizardFormController itself has no control over what exactly the view is sending there. It has to be the form tag in the HTML page including that "_page" attribute, which means that Spring's JSP FormTag and corresponding Velocity/FreeMarker macros would have to render such an attribute automatically. We'll consider this as an enhancement for Spring 2.2.

Juergen

Sayeed Nusrulla Sami added a comment - 30/Jul/07 10:53 PM
Hi Juergen,

The spring form tag is agnostic of where it is being used, it doesnt know whether the jsp in which it is used, is being used by AWFC or SFC or AC,

That is the reason why I thought that the defaultness of handling the _page attribute must be in the AWFC,

Regards
Sami

Juergen Hoeller added a comment - 31/Jul/07 01:01 AM
You've got a point there, of course. However, AWFC cannot render any HTML attributes itself; it can only instruct the view to render something. Which in turn means that the JSP FormTag (or Velocity/FreeMarker form macro) would have to be aware of those instructions... at least in a generic style.

Juergen