Jsf2 Richfaces 4 Fileupload, Display error from Business Logic
I implemented a file upload using jsf2 and richfaces 4. It works quite good with one little mistake.
When i upload my file it can occour that i receive an exception from my business logic. (e.g. file already processed)
How can i manage it to display this exception? I tried to register me for the upload complete and render the form, but with no success.
My Fileupload bean (i tried to set the catched exception over the faces ontext without luck :-/ ) :
public void uploadSvg(FileUploadEvent event) {
UploadedFile uploadedFile = event.getUploadedFile();
File file = writeFileToDisk(uploadedFile);
try {
Utils.getSpringBean(FigureService.class).importFigure(
file.getAbsolutePath());
} catch (Exception e) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
file.getName() + " -> " + e.getMessage(), null);
FacesContext.getCurrentInstance().addMessage(null, message);
log.error(e,e);
// TODO display messages
}
}
My page (i am using it for two different fileuploads. hope that doesn't mind) :
<!DOCTYPE html PUBLIC "-//W3C//DTD XH开发者_开发技巧TML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<body>
<h:form id="files" >
<h:messages errorStyle="color:red" warnStyle="color: yellow" />
<h:panelGrid columns="1">
<h:column>
<c:if test="#{fileType eq 'svg'}">
<rich:fileUpload fileUploadListener="#{fileUpload.uploadSvg}"
maxFilesQuantity="5" id="uploadsvg" immediateUpload="false"
acceptedTypes="svg" allowFlash="false"
uploadData="#{fileUpload.uploadedFiles }" autoclear="false">
<a4j:ajax event="uploadcomplete" execute="@none" render="files"/>
</rich:fileUpload>
</c:if>
<c:if test="#{fileType eq 'fm'}">
<rich:fileUpload fileUploadListener="#{fileUpload.uploadFm}"
maxFilesQuantity="5" id="uploadfm" immediateUpload="false"
acceptedTypes="csv" allowFlash="false"
uploadData="#{fileUpload.uploadedFiles }" autoclear="false">
<a4j:ajax event="uploadcomplete" execute="@none" render="files"/>
</rich:fileUpload>
</c:if>
</h:column>
</h:panelGrid>
</h:form>
</body>
</html>
Thanks a lot! greetings, m
精彩评论