Seam FileUpload Problem
yj4jboss Nov 23, 2006 1:14 AMHello,
I am trying to get the Seam File Upload example (from the wiki) working but i am stuck on one point!!
My configs are as follows:
My web.xml
<?xml version="1.0" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <listener> <listener-class>org.jboss.seam.servlet.SeamListener</listener-class> </listener> <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>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <!-- tomahawk samples --> <context-param> <description>This parameter tells MyFaces if javascript code should be allowed in the rendered HTML output. If javascript is allowed, command_link anchors will have javascript code that submits the corresponding form. If javascript is not allowed, the state saving info and nested parameters will be added as url parameters. Default: "true"</description> <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name> <param-value>false</param-value> </context-param> <context-param> <description>If true, rendered HTML code will be formatted, so that it is "human readable". i.e. additional line separators and whitespace will be written, that do not influence the HTML code. Default: "true"</description> <param-name>org.apache.myfaces.PRETTY_HTML</param-name> <param-value>true</param-value> </context-param> <context-param> <description>If true, a javascript function will be rendered that is able to restore the former vertical scroll on every request. Convenient feature if you have pages with long lists and you do not want the browser page to always jump to the top if you trigger a link or button action that stays on the same page. Default: "false"</description> <param-name>org.apache.myfaces.AUTO_SCROLL</param-name> <param-value>true</param-value> </context-param> <context-param> <description> Validate managed beans, navigation rules and ensure that forms are not nested. </description> <param-name>org.apache.myfaces.VALIDATE</param-name> <param-value>false</param-value> </context-param> <context-param> <description>A class implementing the org.apache.myfaces.shared.renderkit.html.util.AddResource interface. It is responsible to place scripts and css on the right position in your HTML document. Default: "org.apache.myfaces.shared.renderkit.html.util.DefaultAddResource" Follow the description on the MyFaces-Wiki-Performance page to enable StreamingAddResource instead of DefaultAddResource if you want to gain performance. </description> <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name> <param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource</param-value> <!--param-value>org.apache.myfaces.component.html.util.StreamingAddResource</param-value--> </context-param> <context-param> <description> A very common problem in configuring MyFaces-web-applications is that the Extensions-Filter is not configured at all or improperly configured. This parameter will check for a properly configured Extensions-Filter if it is needed by the web-app. In most cases this check will work just fine, there might be cases where an internal forward will bypass the Extensions-Filter and the check will not work. If this is the case, you can disable the check by setting this parameter to false. </description> <param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name> <param-value>true</param-value> </context-param> <!-- --> <!-- tomahawk --> <context-param> <param-name>facelets.LIBRARIES</param-name> <param-value>/WEB-INF/tomahawk.taglib.xml;/WEB-INF/enforcement.taglib.xml</param-value> </context-param> <!-- end tomahawk --> <filter> <filter-name>Seam Exception Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class> </filter> <filter> <filter-name>Seam Redirect Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class> </filter> <!-- tomahawk --> <filter> <filter-name>MyFacesExtensionsFilter</filter-name> <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class> <init-param> <param-name>maxFileSize</param-name> <param-value>20m</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>10k</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>/files</param-value> <description>Set the path where the intermediary files will be stored. </description> </init-param> </filter> <!-- end tomahawk --> <!-- Ajax4jsf --> <filter> <display-name>Ajax4jsf Filter</display-name> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>ajax4jsf</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <filter-mapping> <filter-name>Seam Exception Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>Seam Redirect Filter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping> <!-- tomahawk --> <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry --> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <url-pattern>/faces/myFacesExtensionResource/*</url-pattern> </filter-mapping> <!-- end tomahawk --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.seam</url-pattern> </servlet-mapping> <!-- tomahawk --> <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <url-pattern>*.jsf</url-pattern> </filter-mapping> <!-- end tomahawk --> <!-- JAAS Configurations --> <security-constraint> <web-resource-collection> <web-resource-name>All resources</web-resource-name> <description>Protects all resources</description> <url-pattern>/</url-pattern> </web-resource-collection> <auth-constraint> <role-name>User</role-name> <role-name>Administrator</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/login.seam</form-login-page> <form-error-page>/login_errors.seam</form-error-page> </form-login-config> </login-config> <security-role> <role-name>Administrator</role-name> </security-role> <security-role> <role-name>User</role-name> </security-role> </web-app>
My UploadBackingBean :
package accountingAudit.upload; import org.apache.myfaces.custom.fileupload.UploadedFile; import org.hibernate.validator.NotNull; import org.jboss.seam.annotations.Name; @Name("uploadBean") public class UploadBackingBean { private UploadedFile file; public void setFile(UploadedFile file) { this.file = file; } @NotNull public UploadedFile getFile() { return this.file; } }
The SLSB
package accountingAudit.upload; import javax.annotation.PostConstruct; import javax.ejb.Local; import javax.ejb.Stateless; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.interceptor.Interceptors; import org.apache.myfaces.custom.fileupload.UploadedFile; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.ejb.SeamInterceptor; import org.jboss.seam.log.Log; @Local public interface UploadAction{ public String upload(); @Stateless @Name("upload") @Interceptors(SeamInterceptor.class) public class UploadActionBean implements UploadAction { @Logger private Log log; @In private UploadBackingBean uploadBean; @In private FacesContext facesContext; public String upload() { log.debug("upload()"); UploadedFile file = uploadBean.getFile(); log.debug("Uploading File"); log.debug(file.getName()); facesContext.addMessage(null, new FacesMessage("File Uploaded !! " + file.getName())); return "success"; } } }
My XHTML file is as follows:
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:si="http://sourceforge.net/projects/easysi" xmlns:t="http://myfaces.apache.org/tomahawk" xmlns:enforcement="http://www.enforcement.com/jsf"> <body> <ui:composition template="template.xhtml"> <ui:define name="container"> <f:view> <h:form enctype="multipart/form-data"> <t:inputFileUpload storage="file" value="#{uploadBean.file}"/> <h:commandButton value="Submit" action="#{upload.upload}"/> <h:messages/> </h:form> </f:view> </ui:define> </ui:composition> </body> </html>
My WAR file contains the directory "files" where i want to store my uploaded files. As such the following tomahawk config in my web.xml
<init-param> <param-name>uploadRepositoryPath</param-name> <param-value>/files</param-value> <description>Set the path where the intermediary files will be stored. </description> </init-param>
However, i get the following error message in my logs when i try to upload a file:
org.apache.commons.fileupload.FileUploadException: Processing of multipart/form-data request failed. \files\upload_00000000.tmp (The system cannot find the path specified)
Can anyone suggest what could me wrong in the above configs ??
Regards,
Jankee Yogesh
http://www.m-itc.net