[jboss-user] [JBoss Seam] - Re: Help on s:filleupload

ghiormar do-not-reply at jboss.com
Thu Apr 5 07:57:30 EDT 2007


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 interface

  | package 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 at 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 ?


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034977#4034977

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034977



More information about the jboss-user mailing list