Java Reference
In-Depth Information
public
Resolution catchAttachmentsTooBig(
FileUploadLimitExceededException exc,
HttpServletRequest req, HttpServletResponse resp)
{
return new
RedirectResolution(MessageComposeActionBean.
class
,
"recover")
.addParameter("maximumSize", exc.getMaximum())
.addParameter("postedSize", exc.getPosted());
}
This will set the
maximumSize
and
postedSize
parameters and call the
recover
( ) event handler. So, we add properties for the parameters and a
recover
( ) method in
MessageComposeActionBean
:
public
Resolution recover() {
ValidationError error =
new
LocalizableError(
"maximumUpload", postedSize, maximumSize);
getContext().getValidationErrors().add("attachments", error);
return new
ForwardResolution(COMPOSE);
}
public long
maximumSize, postedSize;
We
add
the
error
message
text
in
the
resource
bundle
and
the
<s:errors> tag in the JSP:
stripesbook.action.MessageComposeActionBean.maximumUpload=\
Total attachment size ({2} bytes) exceeds the limit ({3} bytes).
<div><fmt:message key="messageCompose.attachments"/>
:
</div>
<div><s:errors field="attachments"/></div>
<div class="left">
<c:forEach var="index" begin="0" end="3">
<div><s:file name="attachments[${index}]"/></div>
</c:forEach>
</div>
on the following page, and the user will have a chance to try again,
instead of being sent to a generic error page. That plan came together
rather nicely, wouldn't you say?
We now have a place where we can neatly recover from exceptions. Let's
continue our quest to master the inner workings of Stripes and move
on to the intricate details of URL bindings.
Search WWH ::
Custom Search