5 Replies Latest reply on Mar 4, 2009 4:45 AM by Andrei Markavtsov

    Could anyone provide FileUploadBean?

    Thirupathi Neela Newbie

      I am unable to upload the file using RichFaces fileupload. Could anyone provide the code to fileupload file which has successfully uploaded the file.

      regards
      tneela

        • 1. Re: Could anyone provide FileUploadBean?
          Andrei Markavtsov Apprentice

          Can you please define you configuration or post part of code here ?

          • 3. Re: Could anyone provide FileUploadBean?
            Thirupathi Neela Newbie

            Hi!
            Java method is
            ---------------------------------------------------------
            public void fileUpload(UploadEvent event) throws Exception
            {
            try{
            File f1=new File();
            UploadItem item = event.getUploadItem();
            String fileName=item.getFileName();

            int x=fileName.lastIndexOf("\\");
            String tar=fileName.substring(x+1);
            fileName=tar;
            byte[] data=item.getData();
            String contentType=item.getContentType();
            long length=item.getFile().length();
            System.out.println("item.getFileName()"+item.getFileName());
            System.out.println("item.getContentType()"+item.getContentType());
            System.out.println("item.getFile().length()"+item.getFile().length());
            System.out.println("item.getData()"+item.getFile());
            f1.setData(data);
            f1.setName(fileName);
            f1.setLength(length);
            f1.setMime(contentType);
            setFile1(f1);

            files.add(f1);

            System.out.print("file added" );
            uploadsAvailable--;
            }
            catch(Exception e)
            {
            e.printStackTrace();
            }
            }
            --------------------------------------------------------
            When I upload the file, the following exceptions are thrown
            ---------------------------------------------------------
            17:29:22,579 INFO [STDOUT] item.getFileName()C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ri.war\images\cn_Calendar.gif
            17:29:22,579 INFO [STDOUT] item.getContentType()image/gif
            17:29:22,579 INFO [STDOUT] item.getFile().length()1569
            17:29:22,579 INFO [STDOUT] item.getData()C:\DOCUME~1\tneela\LOCALS~1\Temp\5e1244a0-11fcbeeff71--7f7b17054.upload
            17:29:22,579 INFO [STDOUT] Data is setnull //----> This is always null
            17:29:22,579 INFO [STDOUT] Name is setcn_Calendar.gif
            17:29:22,595 INFO [STDOUT] length is set1569
            17:29:22,595 INFO [STDOUT] Mime is setimage/gif
            17:29:22,595 INFO [STDOUT] file added
            17:29:23,407 ERROR [[default]] Servlet.service() for servlet default threw exception
            javax.el.ELException: /fileUpload.xhtml @41,90 createContent="#{fileUploadBean.paint}": java.lang.NullPointerException
            at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:74)
            at org.ajax4jsf.resource.UserResource.send(UserResource.java:115)
            at org.ajax4jsf.resource.ResourceLifecycle.sendResource(ResourceLifecycle.java:221)
            at org.ajax4jsf.resource.ResourceLifecycle.send(ResourceLifecycle.java:146)
            at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:225)
            at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:141)
            at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:486)
            at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
            at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
            at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            at java.lang.Thread.run(Unknown Source)
            Caused by: java.lang.NullPointerException
            at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:83)
            at org.domain.RecruitmentProject.session.FileUploadBean.paint(FileUploadBean.java:183)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
            at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
            at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
            at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
            at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
            at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
            at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
            at org.domain.RecruitmentProject.session.FileUploadBean_$$_javassist_8.paint(FileUploadBean_$$_javassist_8.java)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
            at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
            at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
            at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
            at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
            at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
            ... 30 more
            17:29:23,407 ERROR [CachedConnectionValve] Application error: default did not complete its transaction
            ----------------------------------------------------------
            web.xml
            ---------------------------------------------------------
            <?xml version="1.0"?>
            <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">
            <!-- Ajax4jsf -->
            <context-param>
            <param-name>org.richfaces.SKIN</param-name>
            <param-value>mySkin</param-value>
            </context-param>
            <!-- Facelets development mode (disable in production) -->
            <context-param>
            <param-name>facelets.DEVELOPMENT</param-name>
            <param-value>true</param-value>
            </context-param>
            <!-- JSF -->
            <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
            </context-param>

            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>


            <filter-name>Seam Multipart Filter</filter-name>
            <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>

            <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>/*</url-pattern>
            </filter-mapping>
            <filter-mapping>
            <filter-name>Seam Multipart Filter</filter-name>
            <url-pattern>/*</url-pattern>
            </filter-mapping>
            <!-- Seam -->

            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>


            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>


            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>

            <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
            </servlet-mapping>
            <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.seam</url-pattern>
            </servlet-mapping>
            <security-constraint>
            <display-name>Restrict raw XHTML Documents</display-name>
            <web-resource-collection>
            <web-resource-name>XHTML</web-resource-name>
            <url-pattern>*.xhtml</url-pattern>
            </web-resource-collection>
            <auth-constraint/>
            </security-constraint>
            <login-config>
            <auth-method>BASIC</auth-method>
            </login-config>
            </web-app>
            -----------------------------------------------------
            Any suggestions,please?

            regards
            tneela

            • 4. Re: Could anyone provide FileUploadBean?
              Thirupathi Neela Newbie

              File.java
              -------------------
              @Name("file")

              public class File {

              private String Name;
              private String mime;
              private long length;
              private byte data[];


              public byte[] getData() {
              return data;
              }
              public void setData(byte[] data) {
              this.data = data;
              System.out.print("Data is set"+this.data);
              }
              public String getName() {
              return Name;
              }
              public void setName(String name) {
              Name = name;
              System.out.print("Name is set"+this.Name);
              }
              public long getLength() {
              return length;
              }
              public void setLength(long length) {
              this.length = length;
              System.out.print("length is set"+this.length);
              }

              public String getMime(){
              return mime;
              }

              public void setMime(String mime) {
              this.mime = mime;
              System.out.print("Mime is set"+this.mime);
              }


              }

              • 5. Re: Could anyone provide FileUploadBean?
                Andrei Markavtsov Apprentice

                Set createTempFiles in FALSE in your web.xml:

                <filter>
                <filter-name>Seam Filter</filter-name>
                <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                <init-param>
                 <param-name>createTempFiles</param-name>
                 <param-value>false</param-value>
                 </init-param>
                </filter>