Probleme Richfaces 4 FileUpload & JSF 2
orkin Aug 1, 2011 3:29 PMHi (sorry for my bad english, I'm french.)
I use richfaces 4.0.Final and JSF 2
I have a problem with de fileUpload's compenent. I have copy the example from the showcase richfaces 4 for fileUploadBean and from richfaces 3.3.3 showcase for UploadedImage Object.
I show you my code but it is the same than showcase :
my file.xhtml :
<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">
<h:outputStylesheet>
.top {
vertical-align: top;
}
.info {
height: 202px;
overflow: auto;
}
</h:outputStylesheet>
<rich:panel>
<h:form>
<h:panelGrid columns="2" columnClasses="top,top">
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
id="upload" acceptedTypes="jpg, gif, png, bmp">
<a4j:ajax event="uploadcomplete" execute="@none" render="info" />
</rich:fileUpload>
<h:panelGroup id="info" layout="block" rendered="#{fileUploadBean.size > 0}">
<rich:panel bodyClass="info">
<f:facet name="header">
<h:outputText value="Uploaded Files Info" />
</f:facet>
<h:outputText value="No files currently uploaded" />
<rich:dataGrid columns="1" value="#{fileUploadBean.files}"
var="file" rowKeyVar="row">
<rich:panel bodyClass="rich-laguna-panel-no-header">
<h:panelGrid columns="2">
<a4j:mediaOutput element="img" mimeType="image/jpeg"
createContent="#{fileUploadBean.paint}" value="#{row}"
style="width:100px; height:100px;" cacheable="false">
<f:param value="#{fileUploadBean.timeStamp}" name="time" />
</a4j:mediaOutput>
<h:panelGrid columns="2">
<h:outputText value="File Name:" />
<h:outputText value="#{file.name}" />
<h:outputText value="File Length(bytes):" />
<h:outputText value="#{file.length}" />
</h:panelGrid>
</h:panelGrid>
</rich:panel>
</rich:dataGrid>
</rich:panel>
<br />
<a4j:commandButton action="#{fileUploadBean.clearUploadData}"
render="info, upload" value="Clear Uploaded Data" />
</h:panelGroup>
</h:panelGrid>
</h:form>
</rich:panel>
</html>
my fileUploadBean :
@ManagedBean(name = "fileUploadBean")
@SessionScoped
public class FileUploadBean implements Serializable {
private static final long serialVersionUID = 8301770521196265438L;
private ArrayList<UploadedImage> files = new ArrayList<UploadedImage>();
public FileUploadBean() {
}
public void paint(OutputStream stream, Object object) throws IOException {
stream.write(getFiles().get((Integer) object).getData());
stream.close();
}
public void listener(FileUploadEvent event) throws Exception {
UploadedFile item = event.getUploadedFile();
UploadedImage file = new UploadedImage();
file.setLength(item.getData().length);
file.setName(item.getName());
file.setData(item.getData());
files.add(file);
}
public String clearUploadData() {
files.clear();
return null;
}
public int getSize() {
if (getFiles().size() > 0) {
return getFiles().size();
} else {
return 0;
}
}
public long getTimeStamp() {
return System.currentTimeMillis();
}
public ArrayList<UploadedImage> getFiles() {
return files;
}
public void setFiles(ArrayList<UploadedImage> files) {
this.files = files;
}
}
and my UploadedImage.java
public class UploadedImage {
private int length;
private String name;
private byte[] data;
public UploadedImage() {
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
The component fileUpload bug because I don't have the "style" of buttons :
Left before upload and right after. (I have just the message "Aucune information de style ne semble associée à ce fichier XML. L'arbre du document est affiché ci-dessous.")
This problem is not very important for me but just for style.
My real problem is when I click on Upload button the listener fileUploadBean.listener is not call and I don't know why. For me all is OK and I don't find anything to help me with my problem. Other method of my class are called but the listener is not call.
I attach my web.xml
I don't need specialy this component richfaces fileUpload but i need upload file, if anybody can help me to fix my problem where can I find code for uploadFile with Richfaces 4.0.Final and JSF2
I hope someone can help me, thx for help in advance
Orkin
-
web.xml 1.4 KB
