-
15. Re: Simplest <s:fileUpload> usage
evl123 May 30, 2007 6:20 PM (in response to yuwono)"shane.bryzak@jboss.com" wrote:
We recommend that you don't use the Tomahawk components. If you use the file upload control provided by Seam then you get all the things you mentioned (file name, content type, etc).
Shane,
Sorry but could you detail a bit more about file upload control provided by Seam?
Do you mean something like this:
<s:fileUpload data="#{uploadAction.uploadedFile}" />
(..where uploadedFile is component of type org.apache.myfaces.custom.fileupload.UploadedFile)
I tried this but the result is the same - null uploadedFile inside non-null uploadBean.
However, if I specify uploadedFile to be byte[], it will work because it uploads byte stream instead of UploadedFile class type.
With byte[], I can only get the content and the size but not other meta attributes of the file.
Is there an example of how to use Seam's upload somewhere that I can take a look?
Thanks,
landrew -
16. Re: Simplest <s:fileUpload> usage
evl123 May 30, 2007 6:52 PM (in response to yuwono)"evl123" wrote:
"shane.bryzak@jboss.com" wrote:
We recommend that you don't use the Tomahawk components. If you use the file upload control provided by Seam then you get all the things you mentioned (file name, content type, etc).
Shane,
Sorry but could you detail a bit more about file upload control provided by Seam?
Do you mean something like this:
<s:fileUpload data="#{uploadAction.uploadedFile}" />
(..where uploadedFile is component of type org.apache.myfaces.custom.fileupload.UploadedFile)
Oops, that is tomahawk. Ok, that's goofy of me. I guess what I'm trying to find out is:
1. What jar file to download to get Seam's own upload component
2. Is <s:fileUpload> correct tag to use?
Thanks,
landrew -
17. Re: Simplest <s:fileUpload> usage
shane.bryzak May 31, 2007 3:01 AM (in response to yuwono)"evl123" wrote:
Oops, that is tomahawk. Ok, that's goofy of me. I guess what I'm trying to find out is:
1. What jar file to download to get Seam's own upload component
2. Is <s:fileUpload> correct tag to use?
You need jboss-seam-ui.jar, and yes, <s:fileUpload> is the correct tag. It's documented in the controls chapter of the Seam reference documentation. -
18. Re: Simplest <s:fileUpload> usage
hispeedsurfer May 31, 2007 7:38 AM (in response to yuwono)Hi Shane,
have updated the fileupload example in JIRA.
Have tested and should explode-able on JBoss-4.2.0.GA. -
19. Re: Simplest <s:fileUpload> usage
evl123 May 31, 2007 2:59 PM (in response to yuwono)"shane.bryzak@jboss.com" wrote:
You need jboss-seam-ui.jar, and yes, <s:fileUpload> is the correct tag. It's documented in the controls chapter of the Seam reference documentation.
Thanks Shane.
Now, on the JSF Action Listener side, what class and from what jar file do I need for the uploaded file's Backing Bean to have Seam inject the uploaded file into?
jboss-seam-ui.jar is for front-end tag but I still couldn't find the backend bean to catch the file.
So far, I've only been successful following an example that uses primitive type byte[] with gives only size but not meta attributes like filename. I want to be able to upload in Seam in a similar way as done through Struts FormFile class.
Thanks again. -
20. Re: Simplest <s:fileUpload> usage
shane.bryzak May 31, 2007 9:32 PM (in response to yuwono)"evl123" wrote:
Now, on the JSF Action Listener side, what class and from what jar file do I need for the uploaded file's Backing Bean to have Seam inject the uploaded file into?
jboss-seam-ui.jar is for front-end tag but I still couldn't find the backend bean to catch the file.
So far, I've only been successful following an example that uses primitive type byte[] with gives only size but not meta attributes like filename. I want to be able to upload in Seam in a similar way as done through Struts FormFile class.
Thanks again.
There is no need for any special backing bean, you just bind whichever of the file's properties you need (data, filename, content type) directly to your component. The documentation in CVS explains which properties are available, but it seems you need data, contentType and fileName. -
21. Re: Simplest <s:fileUpload> usage
morellon Jun 1, 2007 10:25 AM (in response to yuwono)hi shane,
my s:fileupload was with rendered false. and the component where i did binding was null.
wiht your alteration it works ok.
thank you! -
22. Re: Simplest <s:fileUpload> usage
evl123 Jun 1, 2007 12:34 PM (in response to yuwono)"shane.bryzak@jboss.com" wrote:
There is no need for any special backing bean, you just bind whichever of the file's properties you need (data, filename, content type) directly to your component. The documentation in CVS explains which properties are available, but it seems you need data, contentType and fileName.
Shane, Thank you!! It works!! Really Cool sir : ) -
23. Re: Simplest <s:fileUpload> usage
hispeedsurfer Jun 1, 2007 5:17 PM (in response to yuwono)@morellon
which alteration you mean?
My binding is always null.
Thanks -
24. Re: Simplest <s:fileUpload> usage
cavani Jun 1, 2007 7:51 PM (in response to yuwono)"hispeedsurfer" wrote:
@morellon
which alteration you mean?
My binding is always null.
Thanks
this one:
http://fisheye.labs.jboss.com/changelog/JBoss/jboss-seam?cs=MAIN:sbryzak2:20070601012425
The same form is used for upload and download. The (Seam JavaBean) component used to bind values in tag was null with rendered false for tag and showing a link for dowload. Otherwise, the component is not null and upload works.
Thanks, -
25. Re: Simplest <s:fileUpload> usage
hispeedsurfer Jun 2, 2007 7:53 AM (in response to yuwono)in my case I see a upload field with button. But the values for file, filename and contenttype in the backing bean are always null and getter/setter are never called only I comment the s:fileupload. In ohter forms in my app there is no problem with fileupload only in this one.
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:a="https://ajax4jsf.dev.java.net/ajax" xmlns:rich="http://richfaces.ajax4jsf.org/rich" xmlns:t="http://myfaces.apache.org/tomahawk"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>sonderfreigabe</title> <link href="./stylesheet/theme.css" rel="stylesheet" type="text/css" /> <link href="./stylesheet/date.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="bodycontent"> <div id="north"> <div id="info"> <div id="text" class="infos">| Imprint | Contact | 02/23/2007</div> </div> <div id="corporateID"> <div id="hdrLogo"><img src="img/logo3.png" alt="logo" /></div> </div> <div id="bradgrum" class="infos"> </div> <div id="status"> <a:status> <f:facet name="start"> <h:graphicImage value="/img/mozilla_blu.gif"></h:graphicImage> </f:facet> <f:facet name="stop"> <h:graphicImage value="/img/connect_idle.gif"></h:graphicImage> </f:facet> </a:status></div> </div> <div id="west"> <h:form> <a:commandLink action="#{specialreleaseeditor.create}" value="New Specialrelease" reRender="center" immediate="true"></a:commandLink> </h:form> </div> <h:panelGroup id="center"> <h:messages globalOnly="true" styleClass="message"/> <!-- this is included normally with ui:include <div id="content"> <span class="errors"> <h:messages id="mainmassage" globalOnly="true"/> </span> <div id="uppercontent2"> <h:form id="upperform" enctype="multipart/form-data"> <s:validateAll> <div class="formfield" style="float: left; width: 100%;"> <h:panelGrid id="upperPanelGrid" columns="1"> <s:decorate id="descriptionDecorator" template="edit.xhtml"> <ui:define name="label">Description:</ui:define> <h:inputTextarea id="desc" value="#{specialreleaseeditor.description}" required="true"> <a:support event="onblur" reRender="descriptionDecorator"/> </h:inputTextarea> <br /> </s:decorate> <s:decorate> <h:panelGrid id="fileugrid"> <h:outputLabel for="fileupload">File</h:outputLabel> <s:fileUpload id="fileupload" data="#{specialreleaseeditor.file}" accept="*/*" fileName="#{specialreleaseeditor.fileName}" contentType="#{specialreleaseeditor.fileContentType}"/> <br /> <s:message></s:message> </h:panelGrid> </s:decorate> <h:panelGrid columns="1" id="grid"> <a:commandLink id="reg" value="Save" action="#{specialreleaseeditor.save}" reRender="center"/> <a:commandLink id="can" value="Cancel" action="#{specialreleaseeditor.cancel}" reRender="center" immediate="true"/> </h:panelGrid> </h:panelGrid> </div><!-- End class formfield --> </s:validateAll> </h:form> </div><!-- End uppercontend --> <div id="lowercontent2"> </div><!-- End lowercontent --> </div><!-- End content--> --> </h:panelGroup> </div> </body> </html>
If I fill the form an press save UIFileUpload.decode() / processUpdates() called but they are no part of MultipartRequest. -
26. Re: Simplest <s:fileUpload> usage
evl123 Jun 4, 2007 8:20 PM (in response to yuwono)Hi Shane,
I'd like to report an error and apologize to user evl123. My userid is landrew but for some reason, there's a mix-up that started happening when I submitted an instant reply a few days ago. Since then, my replies were submitted in evl123 userid. I didn't really pay attention to this error (thinking that it could be a temporary alias for my postings because I just joined the forum). Until a few minutes ago when I clicked on profile of evl123 and found that the userid belongs to another user. Again, I'd like to inform this error to the forum and hope this would be corrected soon (if this reply still goes in as evl123 user's.)
On the s:fileUpload, now I have an issue regarding the file size exceeding a configured limit. When that happens, an HTTP code 500 returns with the following message:
java.lang.RuntimeException: Multipart request is larger than allowed size
I could not find a way to catch this exception and customize it. I found this page (which mentions the same issue):
http://jira.jboss.com:8080/jira/browse/JBSEAM-1239?page=all&decorator=printable
However, I have no idea how to resolve this exception.
The following is my configuration in components.xml
<web:multipart-filter create-temp-files="true"
max-request-size="10000"
url-pattern="*.seam" />
I would appreciate any advice on how to handle this exception.
Thanks again,
landrew -
27. Re: Simplest <s:fileUpload> usage
nathandennis Jun 5, 2007 12:42 AM (in response to yuwono)I?m very glad to see the topic of s:upload being discussed, because I too am having problems. I have managed to get s:upload to do exactly what I want with just one file upload box on a page. But my goal is multiple file upload boxes on the same page. What im doing is linking the data and fileName attributes directly to an entity bean that contains my getters and setters. In the getter method for a the column in my db where I want to store the name of each filename I added some code to write the file to a directory on my server then return the file name. pretty simple I thought. But running to problems I don?t understand
1. the only name I can give the fileName attribute is fileName? I know,,, sounds bazaar. But it seems to be the case
2. if I add the second upload box with different targets, the first box fileName will persist fine,, but and a blank file is written to disk,,, but content is null.
Any help or criticism will be greatly appreciated.
Using seam 1.2.1 and jboss 4.0.5<a:outputPanel id="loadresults1"> <s:decorate id="photo1" template="layout/edit.xhtml"> <ui:define name="label">Photo 1:</ui:define> <s:fileUpload data="#{inventoryHome.instance.picture}" fileName="#{inventoryHome.instance.fileName}" accept="" /> <h:commandButton id="buttonpic1" value="Upload" action="#{inventoryHome.update}" rendered="#{inventoryHome.managed}" reRender="loadresults1"> <a:support event="onkeyup" actionListener="#{inventoryHome.update}" reRender="loadresults1" /> </h:commandButton> <h:commandButton id="delete" value="Delete" action="#{inventoryHome.instance.setPhoto1(null)}" rendered="#{inventoryHome.managed}"/> </s:decorate> <h:graphicImage id="picture" value="/upLoads/#{inventoryHome.instance.photo1}" /> </a:outputPanel> <a:outputPanel> <s:decorate id="photo2" template="layout/edit.xhtml"> <ui:define name="label">Photo 2:</ui:define> <s:fileUpload data="#{inventoryHome.instance.picture2}" fileName="#{inventoryHome.instance.fileName2}" accept="" /> <h:commandButton id="buttonpic2" value="Upload" action="#{inventoryHome.update}" rendered="#{inventoryHome.managed}" reRender="loadresults1"> <a:support event="onkeyup" actionListener="#{inventoryHome.update}" reRender="loadresults2" /> </h:commandButton> <h:commandButton id="delete2" value="Delete" action="#{inventoryHome.instance.setPhoto2(null)}" rendered="#{inventoryHome.managed}"/> </s:decorate> <h:graphicImage id="picture2" value="/upLoads/#{inventoryHome.instance.photo2}" /> </a:outputPanel> -------------------------- entity bean @Column(name = "photo1", length = 30) @Length(max = 30) public String getPhoto1() { try{ // first create dir for file - not needed ofcourse File os = new file("/usr/local/jboss/server/default/deploy/foo.ear/" + "foo.war/upLoads"); os.mkdirs(); // create empty file with specified name and path os = new file("/usr/local/jboss/server/default/deploy/" + "foo.ear/" + "foo.war/upLoads/"+getFileName()); FileOutputStream oStream =new FileOutputStream(os); oStream.write(getPicture()); this.photo1=getFileName(); // this.picture=null; }catch(Exception e){ // e.printStackTrace(); } return this.photo1; } public void setPhoto1(String photo1) { this.photo1 = photo1; } @Column(name = "photo2", length = 30) @Length(max = 30) public String getPhoto2() { try{ // create empty file with specified name and path File os2 = new File("/usr/local/jboss/server/default/deploy/" + "foo.ear/" + "crookmotors.war/upLoads/"+getFileName2()); FileOutputStream oStream =new FileOutputStream(os2); oStream.write(getPicture2()); this.photo2=getFileName2(); // this.picture=null; }catch(Exception e){ // e.printStackTrace(); } return this.photo2; } public void setPhoto2(String photo2) { this.photo2 = photo2; } public byte [] getPicture() { return this.picture; } public void setPicture(byte [] picture) { this.picture = picture; } public byte [] getPicture2() { return this.picture2; } public void setPicture2(byte [] picture2) { this.picture2 = picture2; public String getFileName() { return this.fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getFileName2() { return this.fileName; } public void setFileName2(String filename2) { this.filename2 = filename2; ...
InventoryHome is an unaltered session bean from seam gen
what am i missing???
like i said,, this worked fine will only one field. -
28. Re: Simplest <s:fileUpload> usage
shane.bryzak Jun 5, 2007 11:48 AM (in response to yuwono)I tested this by adding a second s:fileUpload to the registration form in the seamspace example, and while the data for the second file wasn't null, it was partially truncated. I've created a JIRA issue for this and I'll fix it in the next day or so.
http://jira.jboss.org/jira/browse/JBSEAM-1395 -
29. Re: Simplest <s:fileUpload> usage
nathandennis Jun 5, 2007 3:51 PM (in response to yuwono)thanks shane,
i was hoping i was that lost..