Richfaces 4, JSF2, Fileupload render Problem
max_kuffs Aug 26, 2011 4:25 AMhello,
I am currenctly develop a fileupload which works quite fine. I can upload and process my files perfectly, but i am missing the refresh which was shown in the showcase.
In my file processing exception can occour in the business logic and i would like to have them displayed in the interface. I tried many things, but couldn't get it to work.
I also tried the showcase where the refreshing worked fine. It shows the newly uploaded files as expected. If i change the scope from session to view the refresh doesn't happen anymore. Is session scope required?
Is it possible at all to refresh the <h:messages errorStyle="color:red" warnStyle="color: yellow" /> element this way?
greetings
max
My Bean:
@ManagedBean
@ViewScoped
public class FileUpload implements Serializable {
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 why does this not show up in the frontend???
}
}
....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 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"
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"
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>