-
1. Re: Help on s:filleupload
stu2 Mar 8, 2007 3:16 PM (in response to xigua)It looks like you're reading in the file even if one wasn't selected for uploading. In my file upload bean I check to see if a file was actually uploaded. If not, don't read it in. Here's how it looks for me:
if (uploadFile == null) { error("Hmm. uploaded file data is null!"); return; }
Could this be your problem? -
2. Re: Help on s:filleupload
xigua Mar 8, 2007 5:29 PM (in response to xigua)"stu2" wrote:
It looks like you're reading in the file even if one wasn't selected for uploading. In my file upload bean I check to see if a file was actually uploaded. If not, don't read it in. Here's how it looks for me:if (uploadFile == null) { error("Hmm. uploaded file data is null!"); return; }
Could this be your problem?
I don't think so since the NPE happens in org.jboss.seam.ui.FileUpload.decode
Maybe I misunderstood.
So I have a backing bean which has a InputSteam field and there are getter and setter for it. So on the front end, I use <s:fileUpload data="#{backingbean.filedata}" />. My understanding is that if user select the file, then the file will be uploaded and set to the InputStream field otherwise set it to null, I didn't try to read the file at all. It seems to me that once I use fileUpload component and bind it to a field of the backing bean, the seam component will try to read the file no matter whether there is file selected? -
3. Re: Help on s:filleupload
stu2 Mar 8, 2007 5:36 PM (in response to xigua)Ahh, we're using it differently. I'm following the seam examples, where the upload componet sets the value to a bean variable that is a byte []. For instance this is from my backing bean (with the obvious getters/setters left out):
private String uploadFileName; private byte [] uploadFile;
and here's what the facelets page looks like:<s:fileUpload id="feed" data="#{feedMapping.uploadFile}" fileName="#{feedMapping.uploadFileName}"/>
That plus the null check from my previous post works well for me, and I don't get the nullpointer you're seeing.
Does that help? -
4. Re: Help on s:filleupload
shane.bryzak Mar 9, 2007 8:02 AM (in response to xigua)The NPE is fixed in Seam 1.1.7 and higher. I recommend you update to the latest release.
-
5. Re: Help on s:filleupload
xigua Mar 9, 2007 10:59 AM (in response to xigua)"shane.bryzak@jboss.com" wrote:
The NPE is fixed in Seam 1.1.7 and higher. I recommend you update to the latest release.
Thanks a lot. And I confirmed that NPE only exists if I use InputStream instead of byte[]. -
6. Re: Help on s:filleupload
carloszaniolo Mar 9, 2007 2:46 PM (in response to xigua)BTW s:fileupload is not working together with Ajax4jsf! Does anyone knows how to make s:fileupload works in an "Ajax" way?
-
7. Re: Help on s:filleupload
carloszaniolo Mar 9, 2007 3:45 PM (in response to xigua)"carloszaniolo" wrote:
BTW s:fileupload is not working together with Ajax4jsf! Does anyone knows how to make s:fileupload works in an "Ajax" way?
http://jboss.com/index.html?module=bb&op=viewtopic&p=4026758#4026758 -
8. Re: Help on s:filleupload
ghiormar Apr 5, 2007 7:57 AM (in response to xigua)Is it normal behavior for the <s:fileUpload> to call the setter for byte[] twice? I'm mean first it calls it for the byte[] with the file data and then it calls it with a null. I used seam 1.2.1.GA on jboss 4.0.5.GA. The project was build with seam-gen.
package app.beans.entity; import javax.ejb.Remove; import javax.ejb.Stateful; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.core.FacesMessages; import org.jboss.seam.log.Log; @Stateful @Name("uploadFile") @Scope(ScopeType.EVENT) public class UploadFile implements java.io.Serializable, UploadFileI { private static final long serialVersionUID = 940956938635067807L; @Logger private Log log; private byte[] byteArray; private String fileName; private String size; private static int count = 0; public UploadFile() { } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; FacesMessages.instance().add("i'm here set File name = "+this.fileName); } public byte[] getByteArray() { return byteArray; } public void setByteArray(byte[] byteArray) { count++; //SUGESTED FIX // if (byteArray == null) { // FacesMessages.instance().add("i'm here setByteArray("+byteArray+");null count:"+count); // return; // } this.byteArray = byteArray; FacesMessages.instance().add("i'm here setByteArray("+byteArray+"); count:"+count); } public String getSize() {return size;} public void setSize(String size) { this.size = size; FacesMessages.instance().add("i'm here set File size = "+this.size); } @Remove @Destroy public void destroy() { } public void reset() { count=0; } }
the interfacepackage app.beans.entity; import org.jboss.annotation.ejb.Local; @Local public interface UploadFileI { public String getFileName(); public void setFileName(String fileName); public byte[] getByteArray(); public void setByteArray(byte[] byteArray); public String getSize(); public void setSize(String size); public void destroy(); public void reset(); }
the form<!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:s="http://jboss.com/products/seam/taglib" xmlns:h="http://java.sun.com/jsf/html"> <head> <title>Test Upload</title> </head> <body> <h:messages styleClass="message"/> <h:form id="form" enctype="multipart/form-data"> <h:panelGrid columns="2"> <h:outputText value="file name" /> <h:outputText value="#{uploadFile.fileName}" /> <h:outputText value="file size" /> <h:outputText value="#{uploadFile.size}" /> <h:outputText value="file size" /> <h:inputTextarea value="#{uploadFile.byteArray}" /> <s:fileUpload data="#{uploadFile.byteArray}" fileName="#{uploadFile.fileName}" fileSize="#{uploadFile.size}"/> <h:commandButton action="#{uploadFile.reset}" value="reset"></h:commandButton> </h:panelGrid> </h:form> </body> </html>
what to expect* i'm here setByteArray([B@12e0415); count:1 * i'm here set File name = IMG_3332.jpg * i'm here set File size = 1647973 * i'm here setByteArray(null); count:2
I was get NPE when trying to access the 'byteArray' an couldn't figure out why. Since the fileName and size where set ok.
Is this a bug ? -
9. Re: Help on s:filleupload
fhh Apr 5, 2007 9:10 AM (in response to xigua)<h:inputTextarea value="#{uploadFile.byteArray}" /> <s:fileUpload data="#{uploadFile.byteArray}" fileName="#{uploadFile.fileName}" fileSize="#{uploadFile.size}"/>
Is this intended?
Regards
Felix -
10. Re: Help on s:filleupload
ghiormar Apr 5, 2007 9:20 AM (in response to xigua)I missed that. now it's ok. thanks