Hi,
I've a little problem with form population after a multipart request's
file size exceeded. What I do is testing the file size of an uploaded
file in the validate method of a form:
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
String requestAttrName
= MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED;
Object o = request.getAttribute(requestAttrName);
Boolean fileLengthExceeded = (Boolean) o;
if ((fileLengthExceeded != null) &&
fileLengthExceeded.booleanValue()) {
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("maxLengthExceeded"));
}
if (errors.isEmpty()) {
errors = super.validate(mapping, request);
}
return errors;
}
As you can see from the call to super.validate, there are some other
fields which should be validated. When the user filled out these other
fields correctly and uploads a file that is too big, he is forwarded too
input page. So validation works as expected. But the problem is, that
the values of the other fields are gone. A look in the Struts code
reveals why: In RequestUtils#populate you can find the same test for
file size:
Boolean maxLengthExceeded =
(Boolean) request.getAttribute(
MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
if ((maxLengthExceeded != null) &&
(maxLengthExceeded.booleanValue())) {
return;
}
And the method returns immediately, if the file size is too big. That
means *before* the form is populated. So I populatetd the form by myself
in the validate method by reusing code from RequestUtils, just to find,
that that's not the end of the story. In
CommonsMultipartRequestHandler#handleRequest you find again this test
and again *before* the text parameters are set.
Is there any "easy" solution for this problem and is it "stupid" to ask,
why not populate (even if this is only for redisplaying values) the form
or in the case of MultipartRequestHandlers, set the text parameters,
*before* testing the file size and returning?
Thanks in advance
Franz
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]