Revision: 1360 http://stripes.svn.sourceforge.net/stripes/?rev=1360&view=rev Author: bengunter Date: 2010-11-29 15:08:09 +0000 (Mon, 29 Nov 2010)
Log Message: ----------- Applied fix for STS-780 from 1.5.x branch. Modified Paths: -------------- trunk/stripes/src/net/sourceforge/stripes/action/ActionBeanContext.java Added Paths: ----------- trunk/stripes/src/net/sourceforge/stripes/exception/SourcePageNotFoundException.java Modified: trunk/stripes/src/net/sourceforge/stripes/action/ActionBeanContext.java =================================================================== --- trunk/stripes/src/net/sourceforge/stripes/action/ActionBeanContext.java 2010-11-29 15:05:33 UTC (rev 1359) +++ trunk/stripes/src/net/sourceforge/stripes/action/ActionBeanContext.java 2010-11-29 15:08:09 UTC (rev 1360) @@ -28,6 +28,7 @@ import net.sourceforge.stripes.controller.FlashScope; import net.sourceforge.stripes.controller.StripesConstants; import net.sourceforge.stripes.controller.StripesFilter; +import net.sourceforge.stripes.exception.SourcePageNotFoundException; import net.sourceforge.stripes.tag.ErrorsTag; import net.sourceforge.stripes.util.CryptoUtil; import net.sourceforge.stripes.util.Log; @@ -218,14 +219,17 @@ * this method.</p> * * @return Resolution a resolution that will forward the user to the page they came from - * @throws IllegalStateException if the information required to construct a source page - * resolution cannot be found in the request. + * @throws SourcePageNotFoundException if the information required to construct a source page + * resolution cannot be found in the request. * @see #getSourcePage() */ - public Resolution getSourcePageResolution() { + public Resolution getSourcePageResolution() throws SourcePageNotFoundException { String sourcePage = getSourcePage(); if (sourcePage == null) { - return new ValidationErrorReportResolution(getValidationErrors()); + if (StripesFilter.getConfiguration().isDebugMode()) + return new ValidationErrorReportResolution(this); + else + throw new SourcePageNotFoundException(this); } else { return new ForwardResolution(sourcePage); @@ -266,25 +270,18 @@ class ValidationErrorReportResolution implements Resolution { private static final Log log = Log.getInstance(ValidationErrorReportResolution.class); - private ValidationErrors errors; + private ActionBeanContext context; - protected ValidationErrorReportResolution(ValidationErrors errors) { - this.errors = errors; + /** Construct a new instance to report validation errors in the specified context. */ + protected ValidationErrorReportResolution(ActionBeanContext context) { + this.context = context; } public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception { // log an exception for the stack trace - Exception exception = new IllegalStateException( - "Here's how it is. Someone (quite possibly the Stripes Dispatcher) needed " + - "to get the source page resolution. But no source page was supplied in the " + - "request, and unless you override ActionBeanContext.getSourcePageResolution() " + - "you're going to need that value. When you use a <stripes:form> tag a hidden " + - "field called '" + StripesConstants.URL_KEY_SOURCE_PAGE + "' is included. " + - "If you write your own forms or links that could generate validation errors, " + - "you must include a value for this parameter. This can be done by calling " + - "request.getServletPath()."); + SourcePageNotFoundException exception = new SourcePageNotFoundException(this.context); log.error(exception); - + // start the HTML error report response.setContentType("text/html"); PrintWriter writer = response.getWriter(); @@ -297,7 +294,7 @@ sendErrors(request, response); writer.println("</p></body></html>"); } - + protected void sendErrors(HttpServletRequest request, HttpServletResponse response) throws Exception { // Output all errors in a standard format @@ -325,7 +322,7 @@ PrintWriter writer = response.getWriter(); writer.write(header); - for (List<ValidationError> list : errors.values()) { + for (List<ValidationError> list : this.context.getValidationErrors().values()) { for (ValidationError fieldError : list) { writer.write(openElement); writer.write(fieldError.getMessage(locale)); Added: trunk/stripes/src/net/sourceforge/stripes/exception/SourcePageNotFoundException.java =================================================================== --- trunk/stripes/src/net/sourceforge/stripes/exception/SourcePageNotFoundException.java (rev 0) +++ trunk/stripes/src/net/sourceforge/stripes/exception/SourcePageNotFoundException.java 2010-11-29 15:08:09 UTC (rev 1360) @@ -0,0 +1,54 @@ +/* Copyright 2010 Ben Gunter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.sourceforge.stripes.exception; + +import net.sourceforge.stripes.action.ActionBeanContext; +import net.sourceforge.stripes.controller.StripesConstants; + +/** + * A subclass of {...@link IllegalStateException} that is thrown when validation errors are present on + * a request and the source page cannot be determined. + * + * @author Ben Gunter + * @since Stripes 1.5.5 + */ +public class SourcePageNotFoundException extends IllegalStateException { + private ActionBeanContext actionBeanContext; + + /** + * Construct a new instance for the given action bean context. + * + * @param actionBeanContext The context. + */ + public SourcePageNotFoundException(ActionBeanContext actionBeanContext) { + // @formatter:off + super( + "Here's how it is. Someone (quite possibly the Stripes Dispatcher) needed " + + "to get the source page resolution. But no source page was supplied in the " + + "request, and unless you override ActionBeanContext.getSourcePageResolution() " + + "you're going to need that value. When you use a <stripes:form> tag a hidden " + + "field called '" + StripesConstants.URL_KEY_SOURCE_PAGE + "' is included. " + + "If you write your own forms or links that could generate validation errors, " + + "you must include a value for this parameter. This can be done by calling " + + "request.getServletPath()."); + // @formatter:on + this.actionBeanContext = actionBeanContext; + } + + /** Get the action bean context in which this exception occurred. */ + public ActionBeanContext getActionBeanContext() { + return actionBeanContext; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Stripes-development mailing list Stripes-development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-development