But shouldn't it at least show the error message?
On Tue, May 20, 2008 at 7:06 PM, Ben Gunter <[EMAIL PROTECTED]> wrote:
> Unfortunately, this is as good as it gets. Take a look at this thread for
> more information.
>
> http://article.gmane.org/gmane.comp.java.stripes.user/1079
>
> -Ben
>
> Samuel Santos wrote:
>
> Thanks Ben for your help, but unfortunately it doesn't work as expected.
>
> It redirects correctly to the form page but loses all the form values and
> error messages.
>
> My handle code:
> public Resolution handle(FileUploadLimitExceededException exception,
> HttpServletRequest request,
> HttpServletResponse response) throws ServletException,
> IOException {
> LOGGER.warn(exception.getMessage());
>
> /*
> * This is a hack from Ben Gunter received in the Stripes forum. It
> is related to Jira issue:
> * http://stripes.mc4j.org/jira/browse/STS-402. The problem is
> that when the exception handler is called, it
> * always receives the original request passed to the StripesFilter
> and not the wrapped request. That prevents
> * construction of the FlashScope in which we need to store the
> error message.
> */
> final StripesRequestWrapper wrapper = new
> StripesRequestWrapper(request) {
> /**
> * Ignore multipart content and set the locale at the same
> time.
> *
> * @param request the HTTP request to wrap.
> */
> @Override
> protected void constructMultipartWrapper(HttpServletRequest
> request) throws StripesServletException {
> Locale locale =
> StripesFilter.getConfiguration().getLocalePicker().pickLocale(request);
> setLocale(locale);
> }
> };
>
> // get referer URL
> URL referer = null;
> try {
> referer = new URL(request.getHeader("referer"));
> } catch (Exception e) {
> throw exception;
> }
>
> // convert referer path to context-relative path
> String path = referer.getFile();
> String contextPath = request.getContextPath();
> if (contextPath.length() > 0) {
> if (!path.startsWith(contextPath + "/"))
> throw exception;
> path = path.replace(contextPath, "");
> }
>
> // create action bean and context
> Configuration config = StripesFilter.getConfiguration();
> final PVoucherActionBeanContext context =
> (PVoucherActionBeanContext) config.getActionBeanContextFactory()
> .getContextInstance(request, response);
> final ActionBean actionBean =
> config.getActionResolver().getActionBean(context);
>
> // try to guess the field name
> String fieldName = ValidationErrors.GLOBAL_ERROR;
> try {
> BeanInfo beanInfo =
> Introspector.getBeanInfo(actionBean.getClass());
> for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors())
> {
> if (pd.getPropertyType().equals(FileBean.class)) {
> fieldName = pd.getName();
> break;
> }
> }
> } catch (Throwable t) {
> }
>
> // add validation error
> DecimalFormat format = new DecimalFormat("0.00");
> double max = (double) exception.getMaximum() / 1024;
> double posted = (double) exception.getPosted() / 1024;
> context.getValidationErrors().add(fieldName,
> new LocalizableError("error.file.too.large",
> format.format(max), format.format(posted)));
>
> // redirect back to referer
> return new RedirectResolution(path) {
> @Override
> public void execute(HttpServletRequest request,
> HttpServletResponse response) throws ServletException,
> IOException {
> ExecutionContext executionContext = new ExecutionContext();
> executionContext.setActionBean(actionBean);
> executionContext.setActionBeanContext(context);
> DispatcherHelper.fillInValidationErrors(executionContext);
> super.execute(wrapper, response);
> }
> }.flash(actionBean);
> }
>
> --
> Samuel
>
>
> On Tue, May 20, 2008 at 5:15 PM, Ben Gunter <[EMAIL PROTECTED]> wrote:
>
>> You are creating the hacked up StripesRequestWrapper, but you're never
>> using it. Also, we changed how localizable messages are looked up and that
>> would cause an NPE with the code you have. I've done a little more hacking
>> on it, and the following code will work if you make the wrapper final.
>>
>> // redirect back to referer
>> return new RedirectResolution(path) {
>> @Override
>> public void execute(HttpServletRequest request,
>> HttpServletResponse response)
>> throws ServletException, IOException {
>> ExecutionContext exec = new ExecutionContext();
>> exec.setActionBean(actionBean);
>> exec.setActionBeanContext(context);
>> DispatcherHelper.fillInValidationErrors(exec);
>> super.execute(wrapper, response);
>> }
>> }.flash(actionBean);
>>
>>
>>
>> -Ben
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>
>
>
> --
> Samuel Santos
> http://www.samaxes.com/
>
> ------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>
> ------------------------------
>
> _______________________________________________
> Stripes-users mailing [EMAIL
> PROTECTED]://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
--
Samuel Santos
http://www.samaxes.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users