-
1. Re: Fileupload
deniss.parhomenko Feb 24, 2006 1:13 PM (in response to udo.krass)Yes, tomohawk file upload work with seam, you need define extension filter in web.xml and you can you se file upload
-
2. Re: Fileupload
ido_tamir Feb 25, 2006 5:35 PM (in response to udo.krass)My problem is that setFile(UploadedFile file) is never called and file remains null. I tried both tomahawk and adf.
The valueChangeListener version also never activates any bean method.
I can select a file, and after pressing the submit button I am asked by the browser if I really want to submit that file. But in the bean the file is still null.
Any help would be greatly appreciated.
Sincerely
Ido
I have Extensions configured:<filter-name>extensionsFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class> ... <filter-mapping> <filter-name>extensionsFilter</filter-name> <url-pattern>*.jsf</url-pattern> </filter-mapping> <filter-mapping> <filter-name>extensionsFilter</filter-name> <url-pattern>/faces/*</url-pattern> </filter-mapping> ...
And Bean@Stateful @Scope(ScopeType.SESSION) @Name("fileUpload") @Interceptors(SeamInterceptor.class) public class FileUploadAction implements FileUpload { @Destroy @Remove public void destroy() {} private UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; System.err.println("uploaded file: setFile"); } public String doUpload() { UploadedFile tmpfile = getFile(); System.err.println("uploaded file: do upload after" + (tmpfile == null)); return "uploaded"; } }
And in page:<h:form enctype="multipart/form-data" id="myForm" name="myForm"> <t:inputFileUpload storage="file" value="#{fileUpload.file}"/> <h:commandButton value="Submit" action="#{fileUpload.doUpload}"/> </h:form>
-
3. Re: Fileupload
armita Mar 12, 2006 3:39 AM (in response to udo.krass)I am getting a java.lang.IllegalArgumentException: argument type mismatch
for UploadedFile property.
Any idea? -
4. Re: Fileupload
littlesuns Mar 12, 2006 9:16 PM (in response to udo.krass)do you have Getter and Setter for file?
-
5. Re: Fileupload
armita Mar 14, 2006 9:55 AM (in response to udo.krass)Yes I have the setter getter methods!
-
6. Re: Fileupload
ido_tamir Mar 14, 2006 1:42 PM (in response to udo.krass)I don't remember exactly how I solved my problem.
I switched to adf. Then I had to put the adf jars
into the /server/default/lib folder.
I changed some listeners in faces-config.xml
and it works now nicely.
sorry for not being able to make this post more
informative.
best wishes
ido -
7. Re: Fileupload
da.ogre Apr 17, 2006 8:58 AM (in response to udo.krass)Hi all!
I'm having the same problem as described above - using latest seam from cvs, jboss 4.0.4RC1 and facelets, trying to upload a file (an image perticularly). So, I have an entity bean, say a client, with a field of type UploadedFile and the relevant getters and setters:... @Entity @Name("client") @Scope(CONVERSATION) @Table(name="CLIENTS") public class Client implements Serializable{ private UploadedFile uplFile; ... public UploadedFile getUplFile() { return uplFile; } public void setUplFile(UploadedFile uplFile) { this.uplFile = uplFile; } }
I declared the extensions filter in the web.xml descriptor:<filter> <filter-name>ExtensionsFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class> <init-param> <param-name>uploadMaxFileSize</param-name> <param-value>250k</param-value> </init-param> <init-param> <param-name>uploadThresholdSize</param-name> <param-value>100k</param-value> </init-param> </filter> <filter-mapping> <filter-name>ExtensionsFilter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> <filter-mapping> <filter-name>ExtensionsFilter</filter-name> <url-pattern>/faces/ExtensionResource/*</url-pattern> </filter-mapping>
Also, I have a stateful session bean with a conversation scope, which injects the aforementioned client entity bean and, after pressing a button on the page, persists it in a database, etc.
The problem is, the setter of the UploadedFile is never called and I get aCaused by: java.lang.IllegalArgumentException: argument type mismatch
I have put the commons-io-1.2.jar and commons-fileupload-1.1.jar archives in the WEB-INF/lib folder in my war, and also copied the tomahawk.jar in jbossweb-tomcat55.sar\jsf-libs.
Could anyone, who managed to upload a file using seam and tomahawk components, please explain in details the steps taken and the nessessary code to do it properly? Thanks in advance for any feedback (this issue gets me quite confused). :(
PS: I also noticed that if I dont browse a file and hit the button the setter does get called and the actions are performed as expected, but, of course, then I don't have a file uploaded.. I really don't understand :( -
8. Re: Fileupload
da.ogre Apr 17, 2006 9:05 AM (in response to udo.krass)And yes, I read the article Upload Files with JSF and MyFaces on onjava.com, but I just couldn't get it working with Seam.
-
9. Re: Fileupload
marcioendo Apr 17, 2006 9:42 AM (in response to udo.krass)I haven't tried with the latest CVS version of Seam. But i got it working with Seam-beta2 and Jboss-4.0.4-RC1. Here's what I did:
1. You need 2 Seam components. A "backing bean" required by Tomahawk and SLSB to deal with your JSF action:
1a. Backing Bean:@Name("uploadBean") public class UploadBackingBean { private UploadedFile file; public void setFile(UploadedFile file) { this.file = file; } @NotNull public UploadedFile getFile() { return this.file; } }
1b. Action and its interface@Stateless @Name("upload") @Interceptors(SeamInterceptor.class) public class UploadAction implements Upload { private Logger logger; /** * O arquivo que foi enviado. */ @In private UploadBackingBean uploadBean; @In private FacesContext facesContext; @PostConstruct public void init() { logger = Logger.getLogger(this.getClass()); logger.debug("init()"); } public String upload() { logger.debug("upload()"); UploadedFile file = uploadBean.getFile(); logger.debug("Abrindo o arquivo como DOM4J"); logger.debug(file.getName()); facesContext.addMessage(null, new FacesMessage("Nome do arquivo: " + file.getName())); return "success"; } }
@Local public interface Upload { public String upload(); }
2. You need to define a tomahawk.taglib.xml if you want to be able to access your tomahawk upload component via facelets. It shoud go in your .war WEB-INF<?xml version="1.0"?> <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd"> <facelet-taglib> <!-- author: thomas.jachmann@mindmatters.de --> <namespace>http://myfaces.apache.org/tomahawk</namespace> <tag> <tag-name>inputFileUpload</tag-name> <component> <component-type>org.apache.myfaces.HtmlInputFileUpload</component-type> </component> </tag> </facelet-taglib>
A full taglib definition is available here: http://wiki.apache.org/myfaces-data/attachments/Use_Facelets_with_Tomahawk/attachments/tomahawk.taglib.xml
3. Apart from the normal Seam stuff in your web.xml you need to reference whatever is that Tomahawk needs:<!-- My Faces Extensions Filter --> <filter> <filter-name>extensionsFilter</filter-name> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class> <init-param> <param-name>uploadMaxFileSize</param-name> <param-value>100m</param-value> <!-- <description>Set the size limit for uploaded files. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> --> </init-param> <init-param> <param-name>uploadThresholdSize</param-name> <param-value>100k</param-value> <!-- <description>Set the threshold size - files below this limit are stored in memory, files above this limit are stored on disk. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> --> </init-param> <!-- <init-param> <param-name>uploadRepositoryPath</param-name> <param-value>/temp</param-value> <description>Set the path where the intermediary files will be stored. </description> </init-param> --> </filter> <filter-mapping> <filter-name>extensionsFilter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping> <!-- MyFaces Tomahawk Library --> <context-param> <param-name>facelets.LIBRARIES</param-name> <param-value>/WEB-INF/tomahawk.taglib.xml</param-value> </context-param>
4. The HTML would look something like this:<h:form enctype="multipart/form-data"> <t:inputFileUpload storage="file" value="#{uploadBean.file}"/> <h:commandButton value="Submit" action="#{upload.upload}"/> <h:messages/> </h:form>
5. Finally I put the tomahawk.jar and the commons-file-upload.jar and common-io.jar in the .ear that packages the web application and the EJB's. Of course you need to add the class-path in the MANIFEST.MF of the .ear file.Class-Path: jboss-seam.jar commons-fileupload-1.1.jar commons-io-1.2.jar tomahawk.jar
Hope it helps.
Regards.
Marcio Endo -
10. Re: Fileupload
gavin.king Apr 17, 2006 11:49 AM (in response to udo.krass)Thanks Marcio, we need to get this info on the Seam Wiki.
Will you post it there, or give me permission to copy/paste over to there?
TIA -
11. Re: Fileupload
marcioendo Apr 18, 2006 8:32 AM (in response to udo.krass)No problem Gavin.
But could you please copy/paste it to the Wiki for me, I'm not at the office right now and my machine there has temporarily died on me. (Actually I accidently killed my power supply).
Thanks.
Marcio -
-
13. Re: Fileupload
elfuhrer Apr 27, 2006 5:40 AM (in response to udo.krass)I have followed the same approach and I cannot get it working. There's a conversion error in the file upload. Any hints?
12:40:31,375 ERROR [[/seamapp]] Cannot set value for expression '#{FileUpload.file}' to a new value of type org.apache.myfaces.custom.fileupload.UploadedFileDefaultFileImpl javax.faces.el.EvaluationException: Cannot set value for expression '#{FileUpload.file}' to a new value of type org.apache.myfaces.custom.fileupload.UploadedFileDefaultFileImpl at org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:304) at javax.faces.component.UIInput.updateModel(UIInput.java:226) at javax.faces.component.UIInput.processUpdates(UIInput.java:165) at javax.faces.component.UIForm.processUpdates(UIForm.java:85) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:428) at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:153) at org.apache.myfaces.lifecycle.LifecycleImpl.updateModelValues(LifecycleImpl.java:277) at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:81) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:45) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112) at java.lang.Thread.run(Thread.java:595) Caused by: javax.faces.el.EvaluationException: com.sag.training.FileUploadBean$$EnhancerByCGLIB$$41849acb at org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:155) at org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:269) ... 33 more Caused by: javax.faces.el.EvaluationException: Bean: com.sag.training.FileUploadBean$$EnhancerByCGLIB$$41849acb, property: file at org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:372) at org.apache.myfaces.el.PropertyResolverImpl.setValue(PropertyResolverImpl.java:148) ... 34 more Caused by: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.myfaces.el.PropertyResolverImpl.setProperty(PropertyResolverImpl.java:368) ... 35 more
-
14. Re: Fileupload
marcioendo Apr 27, 2006 7:25 AM (in response to udo.krass)I have this working with the JBoss-4.0.4.CR2 and JBoss-SEAM-1.0.0.CR2 so I'll try and post the example with the updates. But I am not at my office's computer right now and I won't be there until later today, so this will have to wait.
I can't say what is happening in your case, but I do recall I had to update the myfaces libraries to the 1.1.2 versions.