Hi all
Having all sorts of problems trying to configure for file uploads using s:uploadFile.
Using Seam 1.2.1 GA and JBoss 4.0.5GA.
My original function was non trivial, so I rigged up a simple example using code found
around this this forum. Unfortunately, it still doesnt quite work.
When I run it debug, and suspend in reset(), I can see in the stack that the file has been
uploaded into the request, but just hasnt been bound to the backing bean. In my non
trivial example, I had a regular h:inputField that was getting bound to the backing bean,
even though the file wasnt. I've also tried with InputStream and byte[], but no joy
on either.
Here is the web page:
<!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:h="http://java.sun.com/jsf/html">
| <head>
| <title>Test Upload</title>
| </head>
| <body>
| <h:messages styleClass="message"/>
| <h:form id="form" enctype="multipart/form-data">
|
| <h:panelGrid columns="2">
| <h:outputText value="file name" />
| <h:outputText value="#{testUploadFile.fileName}" />
|
| <h:outputText value="file size" />
| <h:outputText value="#{testUploadFile.size}" />
|
| <s:fileUpload data="#{testUploadFile.byteArray}"
fileName="#{testUploadFile.fileName}"
fileSize="#{testUploadFile.size}"/>
| <h:commandButton action="#{testUploadFile.reset}"
value="reset"></h:commandButton>
| </h:panelGrid>
| </h:form>
| </body>
| </html>
Here is the backing bean
package com.webcentral.eq.rft.ui;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
|
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.core.FacesMessages;
| import org.jboss.seam.log.Log;
|
| @Stateful
| @Name("testUploadFile")
| @Scope(ScopeType.EVENT)
| public class TestUploadFile implements java.io.Serializable, TestUploadFileI {
| private static final long serialVersionUID = 940956938635067807L;
| @Logger
| private Log log;
| private byte[] byteArray;
| private String fileName;
| private String size;
| private static int count = 0;
| public TestUploadFile() {
| }
| public String getFileName() {
| return fileName;
| }
| public void setFileName(String fileName) {
| this.fileName = fileName;
| FacesMessages.instance().add("i'm here set File name =
"+this.fileName);
| }
| public byte[] getByteArray() {
| return byteArray;
| }
| public void setByteArray(byte[] byteArray) {
| count++;
| // SUGESTED FIX
| // if (byteArray == null) {
| // FacesMessages.instance().add("i'm here
setByteArray("+byteArray+");null count:"+count);
| // return;
| // }
| this.byteArray = byteArray;
| FacesMessages.instance().add("i'm here
setByteArray("+byteArray+"); count:"+count);
| }
| public String getSize() {return size;}
| public void setSize(String size) {
| this.size = size;
| FacesMessages.instance().add("i'm here set File size =
"+this.size);
| }
|
| @Remove @Destroy
| public void destroy() {
| }
| public void reset() {
| count=0;
| }
| }
Here is the backing bean interface
package com.webcentral.eq.rft.ui;
|
| import org.jboss.annotation.ejb.Local;
|
| @Local
| public interface TestUploadFileI {
| public String getFileName();
| public void setFileName(String fileName);
| public byte[] getByteArray();
| public void setByteArray(byte[] byteArray);
| public String getSize();
| public void setSize(String size);
| public void destroy();
| public void reset();
| }
|
Here is the 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">
|
| <session-config>
| <session-timeout>30</session-timeout>
| </session-config>
|
| <context-param>
| <param-name>javax.faces.CONFIG_FILES</param-name>
| <param-value>/WEB-INF/navigation.xml</param-value>
| </context-param>
|
| <!-- AM Policy Agent -->
| <!--
| <filter>
| <filter-name>Agent</filter-name>
|
<filter-class>com.sun.identity.agents.filter.AmAgentFilter</filter-class>
| </filter>
| <filter-mapping>
| <filter-name>Agent</filter-name>
| <url-pattern>/*</url-pattern>
| <dispatcher>REQUEST</dispatcher>
| <dispatcher>INCLUDE</dispatcher>
| <dispatcher>FORWARD</dispatcher>
| <dispatcher>ERROR</dispatcher>
| </filter-mapping>
| -->
| <!-- Ajax4jsf (must come first!) -->
| <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>
| <servlet-name>Faces Servlet</servlet-name>
| <dispatcher>REQUEST</dispatcher>
| <dispatcher>FORWARD</dispatcher>
| <dispatcher>INCLUDE</dispatcher>
| </filter-mapping>
| <context-param>
| <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
|
<param-value>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</param-value>
| </context-param>
|
| <!-- MyFaces 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>10m</param-value>
| </init-param>
| </filter>
| <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>
| <dispatcher>REQUEST</dispatcher>
| <dispatcher>FORWARD</dispatcher>
| <dispatcher>INCLUDE</dispatcher>
| </filter-mapping>
|
| <!-- extension mapping for serving page-independent resources (javascript,
stylesheets, images, etc.) -->
| <filter-mapping>
| <filter-name>MyFacesExtensionsFilter</filter-name>
| <servlet-name>Faces Servlet</servlet-name>
| <dispatcher>REQUEST</dispatcher>
| <dispatcher>FORWARD</dispatcher>
| <dispatcher>INCLUDE</dispatcher>
| </filter-mapping>
|
| <!-- Seam -->
| <listener>
|
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
| </listener>
| <!-- Propagate conversations across redirects -->
| <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>*.seam</url-pattern>
| </filter-mapping>
| <filter>
| <filter-name>Seam Multipart Filter</filter-name>
| <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
| </filter>
| <filter-mapping>
| <filter-name>Seam Multipart Filter</filter-name>
| <url-pattern>*.seam</url-pattern>
| </filter-mapping>
| <filter>
| <filter-name>Seam Redirect Filter</filter-name>
|
<filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>
| </filter>
| <filter-mapping>
| <filter-name>Seam Redirect Filter</filter-name>
| <servlet-name>Faces Servlet</servlet-name>
| </filter-mapping>
| <filter>
| <filter-name>Seam Exception Filter</filter-name>
|
<filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class>
| </filter>
| <filter-mapping>
| <filter-name>Seam Exception Filter</filter-name>
| <servlet-name>Faces Servlet</servlet-name>
| </filter-mapping>
| <!-- JSF -->
| <context-param>
| <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
| <param-value>client</param-value>
| </context-param>
| <!-- context-param>
| <description>
| Use this context parameter to enable compression in MyFaces version 1.1.4
and later.
| </description>
|
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>
| <param-value>false</param-value>
| </context-param-->
| <context-param>
| <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
| <param-value>.xhtml</param-value>
| </context-param>
| <context-param>
| <param-name>facelets.DEVELOPMENT</param-name>
| <param-value>true</param-value>
| </context-param>
|
| <!-- facelets taglibs -->
| <context-param>
| <param-name>facelets.LIBRARIES</param-name>
|
<param-value>/WEB-INF/eq.taglib.xml;/WEB-INF/tomahawk.taglib.xml</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>
|
| <!-- MyFaces -->
| <listener>
|
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
| </listener>
|
| </web-app>
|
Here is the 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/components
http://jboss.com/products/seam/components-1.2.xsd">
|
| <core:init debug="true"
jndi-pattern="rft/#{ejbName}/local"/>
|
| <core:manager concurrent-request-timeout="500"
| conversation-timeout="240000"
| conversation-id-parameter="cid"
| conversation-is-long-running-parameter="clr"/>
|
| <core:pages no-conversation-view-id="/home.xhtml"/>
|
| <core:dispatcher/>
|
| <!-- Note this : see the section in the seam doco on Seam managed transactions
-->
| <core:managed-persistence-context name="entityManager"
auto-create="true"
| persistence-unit-jndi-name="java:/rftEntityManagerFactory"/>
|
| <core:ejb installed="@embeddedEjb@"/>
|
| <web:multipart-filter create-temp-files="true"
max-request-size="10000000" url-pattern="*.seam"/>
|
| </components>
|
I strong suspect something whacky in the config, since the code was taken from this site
for ppl that is actually worked for.
I'm not sure if there are any other config files that are relevant.
Any obvious faults pointed out would be much appreciated.
Regards
Reuben Helms
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4058506#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...