|
From: Tom T. <tom...@pr...> - 2004-05-11 15:59:46
|
Hello Juergen,
Sorry about the late reply :$, but I've tried the changes to
AbstractWizardFromController, and there's something wrong with
the logic in getCurrentPage.
Currently, the page attribute is fetched from the session and cached in
the request on the first call to getCurrentPage; all subsequent calls
will return the value cached in the request. But the session attribute is
later updated (in showPage), so the cached value returned by
getCurrentPage is then wrong.
This results in e.g. the page parameter passed to referenceData being 0
while on page 1.
I have locally changed the implementation into this, which works
correctly:
protected int getCurrentPage(HttpServletRequest request) {
// get attribute from session
Integer pageAttr =3D (Integer)
request.getSession().getAttribute(getPageSessionAttributeName());
if (pageAttr =3D=3D null) {
// if attribute removed from session, try to get it from request
pageAttr =3D (Integer)
request.getAttribute(getPageSessionAttributeName());
if (pageAttr =3D=3D null) {
throw new IllegalStateException("Page attribute [" +
getPageSessionAttributeName() +
"] neither found in session nor in request");
}
} else {
// if attribute present in session...
if
(!pageAttr.equals(request.getAttribute(getPageSessionAttributeName(=
))))
{
// ...but not (equal) in request, expose in request as well
request.setAttribute(getPageSessionAttributeName(),
pageAttr);
}
}
return pageAttr.intValue();
}
Kind regards,
Tom.
On Sun, 2 May 2004 13:09:32 +0200, "j=FCrgen h=F6ller [werk3AT]"
<jue...@we...> said:
> Tom,
>=20=20
> I've just addressed your AbstractWizardFormController issues:
> validatePagesAndFinish checks for page-specific binding errors now, and
> getCurrentPage allows to retrieve the current page at any point in
> request processing. So processFinish still doesn't have a page parameter,
> but you can now invoke getCurrentPage from there.
>=20=20
> Juergen
>=20=20
>=20
> ________________________________
>=20
> Von: spr...@li... im Auftrag von
> Tom Turelinckx
> Gesendet: Mi 28.04.2004 09:38
> An: spr...@li...
> Betreff: [Springframework-developer] minor annoyances
>=20
>=20
>=20
> Hello,
>=20
> While upgrading to spring 1.0.1, I've noticed some minor annoyances that
> may be easy to fix, possibly for 1.0.2:
>=20
> 1. HttpServletBean apparently does not support properties of type
> Resource, because BeanWrapperImpl does not register a Resource property
> editor by default. However, there's no possibility to register custom
> editors with the BeanWrapper used by HttpServletBean. Maybe an
> "initBeanWrapper" protected method could be added here, like initBinder
> in BaseCommandController?
>=20
> 2. Unlike ResourceBundleMessageSource, ResourceBundleViewResolver only
> has a basename property, no basenames property. As we keep controller
> cfg, dao cfg and messages in separate resource files by functional
> domain, it also makes sense to keep the view cfg in different files.
> We're currently using an adapted ResourceBundleViewResolver, but maybe
> this functionality could be added to spring, or maybe there's a good
> reason to keep all view cfg in a single file?
>=20
> 3. In AbstractWizardFormController, it would be useful if processFinish
> had an extra "int submissionPage" parameter (the currentPage value in
> processFormSubmission could be passed to validatePagesAndFinish and on to
> processFinish), though I have no suggestion how to add this in a
> backward-compatible way...
> It would be useful, because some of our legacy stored procedures perform
> validation logic that we can't duplicate in java, i.e. the result of a
> stored procedure could indicate a user-correctable error, which we would
> like to display in the same way as a global validation error, e.g.:
>=20
> protected ModelAndView processFinish( HttpServletRequest request,
> HttpServletResponse response, Object command,
> BindException errors, int page ) throws Exception {
> // stored procedure is called in onSubmit,
> // messageInfo is an output parameter
> MessageInfo messageInfo =3D onSubmit( command );
> if ( messageInfo.isError() ) {
> errors.reject( "", messageInfo.getMessage() );
> return showPage( request, errors, page );
> }
> if ( messageInfo.isWarning() ) {
> return handleWarning( command, messageInfo );
> }
> return handleSuccess( command, messageInfo );
> }
>=20
> Note that getCurrentPage can't be called in processFinish, as we are
> "after processFormSubmission".
>=20
> Even if the page parameter can't be added to processFinish, it would
> still be useful to add it to validatePagesAndFinish:
>=20
> private ModelAndView validatePagesAndFinish(HttpServletRequest request,
> HttpServletResponse response, Object command,
> BindException errors, int currentPage) throws Exception {
>=20
> // in case of binding errors -> show current page
> if (errors.getErrorCount() - errors.getGlobalErrorCount() > 0) {
> return showPage(request, errors, currentPage);
> }
>=20
> for (int page =3D 0; page < pages.length; page++) {
> validatePage(command, errors, page);
> // in case of field errors on a page -> show the page
> if (errors.getErrorCount() - errors.getGlobalErrorCount() > 0) {
> return showPage(request, errors, page);
> }
> }
> // no field errors -> maybe global errors, or none at all
> return processFinish(request, response, command, errors,
> currentPage);
> }
>=20
> The first if was added to ensure the current page is shown again if there
> were binding errors, such as typeMismatch. Otherwise, those errors will
> always result in the first page being shown, instead of the submission
> page where the error actually occured.
>=20
> Also, shouldn't the "if (pages =3D=3D null | pages.length =3D=3D 0)" in s=
etPages
> use "||" instead of "|"?
>=20
> Kind regards,
> Tom.
>=20
>=20
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle 10g.
> Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id=3D3149&alloc_id=3D8166&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle 10g.
> Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id149&alloc_id=8166&op=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|