Java Reference
In-Depth Information
Download email_29/src/stripesbook/ext/MyExceptionHandler.java
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 :
Download email_29/src/stripesbook/action/MessageComposeActionBean.java
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:
Download email_29/res/StripesResources.properties
stripesbook.action.MessageComposeActionBean.maximumUpload=\
Total attachment size ({2} bytes) exceeds the limit ({3} bytes).
Download email_29/web/WEB-INF/jsp/message_compose.jsp
<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>
The user will now see the informative message shown in Figure 13.4 ,
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