Hello,
I am looking at bug MYFACES-668:
"The second issue is Their are two filter parameters
in Myfaces file upload component: uploadThresholdSize
and uploadMaxFileSize(both are required by the Commons
File Upload component) The uploadThresholdSize tells
Common File uploads to keep files in memory that are
less than this size, and uploadMaxFileSize says to
ignore files that take less than this size.If you try
to upload a file that is too large, the current
version of MyFaces ignores all form data, as if the
user submitted an empty form. If we want to signal the
failed upload to the user, we would have to change the
source code of the MultipartRequestWrapper class of
MyFaces and add a
FacesContext.getCurrentInstance().addMessage() to warn
the user. "
The code in MultipartRequestWrapper uses the Apache
Commons class 'DiskFileUpload' to parse the request in
order to discover uploaded files:
List requestParameters = null;
try{
requestParameters =
fileUpload.parseRequest(request);
} catch (FileUploadBase.SizeLimitExceededException e)
{
// TODO: find a way to notify the user about the
fact that the uploaded file exceeded size limit
if(log.isInfoEnabled())
log.info("user tried to upload a file that
exceeded file-size limitations.", e);
The problem is that a web page may have more than 1
File Upload component. The DiskFileUpload class does
not give us a way to know WHICH component is
associated with the larger-than-allowed file, it
merely throws the exception.
I was thinking of the following approach to the
solution:
1. If the SizeLimitExceededException exception is
thrown, a flag is set in the multipartRequestWrapper
instance
2. In the decode method of the File Upload component,
the code checks if this flag is set. If it is, then an
error message is added with the
'FacesContext.getCurrentInstance().addMessage()' API.
Also, since this is an Input component, we set
'isValid' to false.
3. As I mentioned before, there may be more than 1
File Upload component on a web page. Before adding the
message, the code must first check if this message has
already been added (by another instance of FileUpload
component). If not, it is added. Also as a
consequence, it must be a generic error message (not
associated with any particular component):
Something like "One or more uploaded files has
exceeded the threshold size allowed."
I can create a message bundle for this message (for
now, just the English version).
Any comments/suggestions?
Thanks,
Sharath
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com