[jboss-user] [JBoss Seam] - Simplest <s:fileUpload> usage

yuwono do-not-reply at jboss.com
Thu Apr 19 05:56:01 EDT 2007


I've been hanging around for almost two weeks just to make <s:fileUpload> working.
Simply want to add upload file capability to seam-registration. I'm using seam-space
sample as reference and adapt it into stateless version. Not refering to wiki's
samples cause it using tomahawk, I just want to have it plain and simple.

Environment used :
- JBoss AS 4.0.5.GA
- JBoss Seam 1.2.0.Patch1
- JBoss IDE for Eclipse
- default JBoss Seam (upload) jars - no tomahawk.jar, no icefaces, no commons-upload.
- jboss-seam-ui.jar included

components.xml :

<?xml version="1.0" encoding="UTF-8"?>
  | <components xmlns="http://jboss.com/products/seam/components"
  |             xmlns:core="http://jboss.com/products/seam/core"
  |             xmlns:web="http://jboss.com/products/seam/web"
  |             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  |             xsi:schemaLocation=
  |                 "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd 
  |                  http://jboss.com/products/seam/web http://jboss.com/products/seam/web-1.2.xsd 
  |                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd">
  | 
  |     <core:init jndi-pattern="@jndiPattern@"/>
  |     <core:ejb installed="@embeddedEjb@"/>
  | 
  |     <web:multipart-filter create-temp-files="true" 
  |                           max-request-size="1000000" 
  |                           url-pattern="*.seam"/>
  |     
  | </components>


web.xml :

<?xml version="1.0" encoding="UTF-8"?>
  | 
  | <web-app version="2.5"
  |     xmlns="http://java.sun.com/xml/ns/javaee"
  |     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  |     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  | 
  |     <!-- Seam -->
  |     
  |     <listener>
  |         <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
  |     </listener>
  |     
  | 	<filter>
  | 		<filter-name>Seam Filter</filter-name>
  | 		<filter-class>org.jboss.seam.web.SeamFilter</filter-class>
  | 	</filter>
  | 	
  | 	<filter-mapping>
  | 		<filter-name>Seam Filter</filter-name>
  | 		<url-pattern>/*</url-pattern>
  | 	</filter-mapping>
  | 	
  |     <!-- MyFaces -->
  | 	
  |     <listener>
  |         <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  |     </listener>
  |     
  |     <context-param>
  |         <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  |         <param-value>client</param-value>
  |     </context-param>
  | 
  |     <context-param>
  |         <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  |         <param-value>.jspx</param-value>
  |     </context-param>
  |   
  |     <servlet>
  |         <servlet-name>Faces Servlet</servlet-name>
  |         <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  |         <load-on-startup>1</load-on-startup>
  |     </servlet>
  | 
  |     <!-- Faces Servlet Mapping -->
  |     <servlet-mapping>
  |         <servlet-name>Faces Servlet</servlet-name>
  |         <url-pattern>*.seam</url-pattern>
  |     </servlet-mapping>
  | </web-app>


application.xml :

<?xml version="1.0" encoding="UTF-8"?>
  | <application xmlns="http://java.sun.com/xml/ns/javaee" 
  |              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  |              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
  |              version="5">
  |              
  | 	<display-name>Myapp</display-name>
  | 
  | 	<module>
  | 		<web>
  | 			<web-uri>seam-myapp.war</web-uri>
  | 			<context-root>/myapp</context-root>
  | 		</web>
  | 	</module>
  | 	<module>
  | 		<ejb>seam-myapp.jar</ejb>
  | 	</module>
  | 	<module>
  | 	    <java>jboss-seam.jar</java>
  | 	</module>
  |          <module>
  |                   <java>el-api.jar</java>
  |          </module>
  |          <module>
  |                   <java>el-ri.jar</java>
  |          </module>
  | 
  | </application>


jboss-app.xml :

<jboss-app>
  |       <loader-repository> 
  |       seam.jboss.org:loader=myapp
  |       </loader-repository> 
  | </jboss-app>


the view .................

index.jspx :

<?xml version="1.0"?>
  | <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
  |           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="http://www.w3.org/1999/xhtml"
  |           version="2.0">
  | <jsp:output doctype-root-element="html"
  |             doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  |             doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
  | <jsp:directive.page contentType="text/html"/>
  | <html>
  | <body>
  | <f:view>
  | <h:form enctype="multipart/form-data">
  |    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  |       <tr>
  |          <td>Upload Tasks</td>
  | 	  </tr>
  | 	  <tr>
  |          <td width="100%"><br/>File to upload: 
  |          	<s:fileUpload data="#{admin.uploadedFile}"/>
  |          </td>
  |       </tr>
  |       <tr>
  |          <td>
  |          	<h:commandButton value="Submit" action="#{admin.parse}"/>
  |          </td>
  |       </tr>
  |    </table>
  | </h:form>
  | </f:view>
  | </body>
  | </html>
  | </jsp:root>


and the code ..................

Admin.java :

package myapp;
  | 
  | import javax.ejb.Stateless;
  | import org.jboss.seam.annotations.Name;
  | 
  | @Stateless
  | @Name("admin")
  | public class Admin implements AdminI {
  | 	private byte[] uploadedFile;
  | 	
  | 	public void setUploadedFile(byte[] uploadedFile)
  | 	{
  | 		this.uploadedFile = uploadedFile;
  | 	}
  | 	
  | 	public byte[] getUploadedFile()
  | 	{
  | 		return uploadedFile;
  | 	}
  | 	
  | 	public void parse() throws Exception {
  | 		if(uploadedFile != null)
  | 			System.out.println("size = " + uploadedFile.length);
  | 		else
  | 			System.out.println("uploadedFile is null");
  | 	}
  | }


AdminI.java :

package myapp;
  | 
  | import javax.ejb.Local;
  | 
  | @Local
  | public interface AdminI {
  | 	public void parse() throws Exception;
  | 	public byte[] getUploadedFile();
  | 	public void setUploadedFile(byte[] uploadedFile);
  | }


No error, but it always print "uploadedFile is null". What requirements I might missed?
Any help will be appreciated.

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

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



More information about the jboss-user mailing list