This content has been marked as final.
Show 1 reply
-
1. Re: migrate file upload to <s:fileUpload>
binnyg Jan 27, 2009 8:43 PM (in response to roxello.roxxello.googlemail.com)If you want to use s:fileUpload component this is what you should do.
In components.xml add the following snippet. You can set the max file limit.
<component class="org.jboss.seam.web.MultipartFilter"> <property name="createTempFiles">true</property> <property name="maxRequestSize">2097152</property> </component>
In your bean you should define the following properties. You have to strip extra path if client uploads images from IE. IE sends the whole path of the file where as other browsers send the filename.
@Name("uploadComponent") public class CommonUploads { private byte[] image1; private String imageName1; public byte[] getImage1() { return image1; } public void setImage1(byte[] image1) { this.image1 = image1; } public String getImageName1() { return imageName1; } public void save() { // you have access to the byte array } }
In your xhtml
<h:form enctype="multipart/form-data"> <s:fileUpload id="image1" data="#{uploadComponent.image1}" fileName="#{uploadComponent.imageName1}" accept="*.jpg" /> <h:commandButton value="submit" styleClass="button" action="#{uploadComponent.save}" /> </h:form>
You can also add custom error message in your pages.xml
<exception class="org.jboss.seam.web.FileUploadException"> <redirect view-id="#{facesContext.externalContext.requestServletPath}"> <message>File upload failed. Max size allowed is 2MB.</message> </redirect> </exception>
Do not forget to rate if this is helpful.