7 Replies Latest reply on Jun 15, 2011 1:01 PM by SunRay User

    s:fileUpload - null output

    Gurjeet Reyatt Newbie

      I have recently upgraded my jboss from 4.2.1 to 4.3 jeap and seam 2.0.0 to 2.0.1. Since the upgrade s:uploadFile no longer sends any data - inputStream is null.


      components.xml:


      <?xml version="1.0"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:mail="http://jboss.com/products/seam/mail"
       xmlns:persistence="http://jboss.com/products/seam/persistence"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:transaction="http://jboss.com/products/seam/transaction"
       xmlns:web="http://jboss.com/products/seam/web"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd http://jboss.com/products/seam/jms http://jboss.com/products/seam/jms-2.0.xsd http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd">
       <component name="org.jboss.seam.core.init">
        <property name="debug">@debug@</property>
        <property name="jndi-pattern">@jndiPattern@</property>
       </component>
       <core:manager concurrent-request-timeout="1500"
        conversation-id-parameter="c" conversation-timeout="120000" parent-conversation-id-parameter="p"/>
       <component auto-create="true" name="configurationManager">
        <property name="url">@propertiesLocation@</property>
       </component>
       <factory auto-create="true" name="configuration" value="#{configurationManager.configuration}"/>
       <factory auto-create="true" name="configurationMap" value="#{configurationManager.configurationMap}"/>
       <persistence:managed-persistence-context auto-create="true"
        name="entityManager" persistence-unit-jndi-name="java:/EntityManagerFactories/iaas"/>
       <transaction:ejb-transaction/>
       <security:identity authenticate-method="#{authenticator.authenticate}"/>
       <mail:mail-session session-jndi-name="java:/Mail"/>
       <web:multipart-filter create-temp-files="true" max-request-size="1000000" url-pattern="/*"/>
      </components>
      




      web.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- $Id: web.xml 1291 2008-03-31 10:29:53Z nmoorcroft $ -->
      
      <web-app 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"
        version="2.5">
      
        <!-- Seam -->
        <listener>
          <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
        </listener>
      
        <servlet>
          <servlet-name>Seam Resource Servlet</servlet-name>
          <servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>
        </servlet>
        <servlet-mapping>
          <servlet-name>Seam Resource Servlet</servlet-name>
          <url-pattern>/seam/resource/*</url-pattern>
        </servlet-mapping>
        
       <filter>
          <filter-name>Seam Filter</filter-name>
          <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
        </filter>
        <filter-mapping>
          <filter-name>Seam Filter</filter-name>
          <url-pattern>/*</url-pattern>
        </filter-mapping>
      
        <filter>
          <filter-name>Seam Servlet Filter</filter-name>
          <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class>
        </filter>
      
        <!-- JSF -->
        <context-param>
          <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
          <param-value>.xhtml</param-value>
        </context-param>
      
        <context-param>
          <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
          <param-value>server</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>
        <servlet-mapping>
          <servlet-name>Faces Servlet</servlet-name>
          <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
      
        <!-- Facelets -->
        <context-param>
          <param-name>facelets.SKIP_COMMENTS</param-name>
          <param-value>true</param-value>
        </context-param>
      
        <context-param>
          <param-name>facelets.REFRESH_PERIOD</param-name>
          <param-value>2</param-value>
        </context-param>
      
        <context-param>
          <param-name>facelets.DEVELOPMENT</param-name>
          <param-value>true</param-value>
        </context-param>
      
        <context-param>
          <param-name>facelets.DEFAULT_SUFFIX</param-name>
          <param-value>.xhtml</param-value>
        </context-param>
      
        <!-- etc -->
        <session-config>
          <session-timeout>30</session-timeout>
        </session-config>
      
        <welcome-file-list>
          <welcome-file>/index.html</welcome-file>
        </welcome-file-list>
        
      </web-app>




      s:fileUpload usage:



      ...
      <h:form id="uploadUsersForm" *enctype="multipart/form-data"*>
                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" styleClass="form-table details" columnClasses="labels, fields">
                  <h:outputText value="#{messages.uploadassessmentcodes_labelupload}" styleClass="text key" />          
                  <s:fileUpload id="data" 
                                data="#{uploadUser.inputStream}"
                                styleClass="btn-file" />         
                  
                  <s:span styleClass="clear"></s:span>
                  <s:div styleClass="clear rt mgn-rt0">
                    <h:commandButton action="#{uploadUser.save}" value="#{messages.uploadusers_btnupload}" styleClass="btn" />                 
                    <h:commandButton action="back" value="#{messages.uploadusers_btnback}" styleClass="btn" immediate="true"/>
                  </s:div>           
                </h:panelGrid>
            </h:form>
      ...




      bean:


      @Stateful
      @Name("uploadUser")
      public class UploadUserBean implements UploadUser {
      
           @Logger Log log;
           @In EntityManager entityManager;
           @In private Map<String, String> messages;
           @In Configuration configuration;
           private InputStream inputStream;
           
           public void save() {
                boolean errors = false;
                if(inputStream == null) {
                     FacesMessages.instance().addToControlFromResourceBundle("data", "selectFile");
                     return;
                }
                InputStreamReader reader = new InputStreamReader(inputStream);
                
                      ... //more code
           }
           
           public InputStream getInputStream() {
                return inputStream;
           }
           public void setInputStream(InputStream inputStream) {
                this.inputStream = inputStream;
           }
           
           @Remove @Destroy
           public void remove() {}
      }




      Any help will be greatly appreciated.

        • 1. Re: s:fileUpload - null output
          Gurjeet Reyatt Newbie

          Fixed it. Had gravel.jar (jsf lib) including in the build path which reads the httpRequest during the filter chain.

          • 2. Re: s:fileUpload - null output
            Prathamesh Gaddam Novice
            Hi Gurjeet,

            I am facing similar problem. The value passed to the setter method of the bean (FileUpload.java) is always null. Please elaborate the resolution steps, about gravel.jar.

            `
            @Name("fileUpload")
            @Scope(ScopeType.CONVERSATION)
            public class FileUpload {

                 private byte[] uploadedFile=null;
                     // with getter and setter methods
            }
            `

            simpleMail.xhtml
            `
            <a4j:form id="form" enctype="multipart/form-data">
                 <s:fileUpload data="#{fileUpload.uploadedFile}" accept="image/JPEG,images/jpg,images/jpeg"/>
                 <h:commandButton type="submit" value="Upload"/>          
            </a4j:form>
            `
            web.xml
            `
            <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>
            `

            component.xml
            `
            <web:multipart-filter create-temp-files="true"
              max-request-size="1024000" url-pattern="*.seam"/>
            `
            Thank you in advance.
            • 3. Re: s:fileUpload - null output
              Marcio Endo Newbie

              simpleMail.xhtml
              <a4j:form id="form" enctype="multipart/form-data">
                   <s:fileUpload data="#{fileUpload.uploadedFile}" accept="image/JPEG,images/jpg,images/jpeg"/>
                   <h:commandButton type="submit" value="Upload"/>          
              </a4j:form>
              




              You are not calling any action here. Perhaps:


              <h:commandButton type="submit" value="Upload" action="#{myAction.doSomethingWithFileUpload}" />

              • 4. Re: s:fileUpload - null output
                Prathamesh Gaddam Novice
                Thank you for the speedy reply.

                Even I had tried to use

                <h:commandButton action="#{fileUploader.upload}" value="Upload"/>

                where FileUploader.java has:

                public void upload(){
                    display();
                    try{
                         System.out.println("Uploaded File:"+uploadFile);
                    }
                    catch(Exception e){
                         System.out.println("ERROR:"+e);
                    }
                }

                However, same java.lang.NullPointerException is thrown.

                Kindly confirm anything else needs to be implemeted. Why this problem occurs with <s:fileUpload>?
                • 5. Re: s:fileUpload - null output
                  Marcio Endo Newbie

                  Other things I can think of:



                  • Change the <a4j:form> to a <h:form>;

                  • Remove the accept restriction.

                  • web.xml: declaring SeamFilter should be enough. You shouldn't need the Seam Multipart Filter (as it is 'include' in the SeamFilter). Check the web.xml in the first post of this thread.

                  • 6. Re: s:fileUpload - null output
                    Prathamesh Gaddam Novice
                    Thank you for the assistance. However, I had already attempted all these alternatives using <h:form>/<h:commandbutton>,web.xml... and the output is samejava.lang.NullPointerException.

                    When the setter method [fileUpload.uploadedFile()] is invoked by seam <s:fileUpload>, null value is passed, why? I doubt/guess whether, before the request/event reaches FileUpload component it may be intercepted by another listener/other.

                    I'm unable to place a break point at FileUploadRendererBase.doDecode() [c] as suggested in some posts.

                    Kindly assist.

                    Regards 
                    • 7. Re: s:fileUpload - null output
                      SunRay User Newbie
                      FYI: Using Seam 2.2.2.Final.  The request in FileUploadRendererBase.doDecode() is not Multipart when using the a4j tags <h:form>, <h:commandbutton>.