Reputation: 147
I'm uploading files with <t:inputFileUpload
all is working fine but when file is larger from value set in web.xml it doesn't output any error or warning message.
My code:
<h:form id="uploadForm" enctype="multipart/form-data">
<t:inputFileUpload id="fileupload" accept="image/*" storage="file"
value="#{fileUpload.uploadedFile}" styleClass="fileUploadInput"
required="true" validator="epacient.FileUploadValidator" validatorMessage="Napacna vrsta ali prevelika datoteka."/>
<h:message for="fileupload" style="color: red;" />
<br />
<h:commandButton value="Upload" id="fileUploadButton" action="#{fileUpload.upload}" />
<h:message for="uploadForm" style="color: red;" />
</h:form>
If file is to big it should write an error at <h:message
tag, am I wrong?
How can I resolve the problem ?
best regards
Upvotes: 2
Views: 3007
Reputation: 3610
Like Balus C said, it's a well known issue. See: http://issues.apache.org/jira/browse/TOMAHAWK-1381
I think a later version of Tomahwak fixes this.
Upvotes: 0
Reputation: 1108782
You can't do this with Tomahawk. You can however configure the uploadMaxFileSize
in the ExtensionsFilter
, but when it occurs, it will hard-throw a SizeLimitExceededException
which goes beyond all the JSF thing so that the enduser ends up with an ugly HTTP 500 error page. Although you can define custom error pages in web.xml
which should be displayed for certain status codes or exception types only, there's no way that you can get it nicely in a FacesMessage
which you at end can display in a h:message
.
The only way to do this all nicely is to allow unlimited sized uploads or a 1GB limit or so (which may be a pain, but after all, it's just the client's own decision to do so ;) .. to avoid complaining clients, ensure that there's a clear message somewhere at the form about maximum allowed sizes). This way you can take benefit of a real Validator
which will display the ValidatorException
in the associated h:message
, e.g:
private static final long MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
if (((UploadedFile) value).getSize() > MAX_FILE_SIZE) {
throw new ValidatorException(new FacesMessage("Sorry, max 10MB allowed."));
}
}
Upvotes: 4