0 Replies Latest reply on Jun 6, 2008 10:31 PM by Juan Vargas

    Upload Files

    Juan Vargas Newbie

      Hello friends, i'm having problems with the component s:fileupload when it comes to SFSB brings value null in the data and the file and not throw exceptions


      here is my 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:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:web="http://jboss.com/products/seam/web"
                  
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd">
      
         <core:init debug="true" jndi-pattern="@jndiPattern@"/>
           
         <core:manager concurrent-request-timeout="500" 
                       conversation-timeout="120000" 
                       conversation-id-parameter="cid"/>
          
         <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                            persistence-unit-jndi-name="java:/FONACITEntityManagerFactory"/>                          
      
         <drools:rule-base name="securityRules">
             <drools:rule-files>
                 <value>/security.drl</value>
             </drools:rule-files>
         </drools:rule-base>
      
         <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
         
         <event type="org.jboss.seam.security.notLoggedIn">
             <action execute="#{redirect.captureCurrentView}"/>
         </event>
         <event type="org.jboss.seam.security.loginSuccessful">
             <action execute="#{redirect.returnToCapturedView}"/>
         </event>
         
         <mail:mail-session host="localhost" port="2525" username="test" password="test" />
              
         <!-- For use with jBPM pageflow or process management -->
         <!--  
         <bpm:jbpm>
            <bpm:process-definitions></bpm:process-definitions>
            <bpm:pageflow-definitions></bpm:pageflow-definitions>
         </bpm:jbpm>
         -->
          <component class="org.jboss.seam.web.MultipartFilter">
          <property name="createTempFiles">true</property>
          <property name="maxRequestSize">4194304</property>
      </component>
                                
        
      </components>
      


      my 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>blueSky</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>
        <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>
       <!-- 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.SeamResourceServlet</servlet-class>
       </servlet>
       <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>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>
       <session-config>
        <session-timeout>5</session-timeout>
       </session-config>
       <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>
      


      the SFSB


      package org.domain.FONACIT.session;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.faces.FacesMessages;
      import org.domain.FONACIT.entity.Tauditoria;
      import org.domain.FONACIT.entity.Tfiltros;
      import org.domain.FONACIT.entity.Tlote;
      import org.domain.FONACIT.entity.Treportes;
      
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.util.*;
      
      @Stateful
      @Name("uploadUser")
      @Scope(ScopeType.CONVERSATION)
      public class AdministrarReportesBean implements AdministrarReportes {
      
           
           @In EntityManager entityManager;
           @In private Map<String, String> messages;
           @In(required=false)
           private InputStream inputStream;
           @In(required=false)
           String ruta;
           
           @In(required=false)
           Treportes reporte;
           
           public void save() {
                boolean errors = false;
                if(inputStream == null) {
                     System.out.println("Nuloo");
                     //FacesMessages.instance().addToControlFromResourceBundle("data", "selectFile");
                     //return;
                }
                //InputStreamReader reader = new InputStreamReader(inputStream);
                System.out.println("Data: "+inputStream);//shows null
              System.out.println("ruta "+reporte.getDirecrepor());       
           }
           
           public InputStream getInputStream() {
                return inputStream;
           }
           public void setInputStream(InputStream inputStream) {
                this.inputStream = inputStream;
           }
           
           @Remove @Destroy
           public void remove() {}
      }



      the page


      <ui:composition 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:a4j="http://richfaces.org/a4j"
           xmlns:rich="http://richfaces.org/rich"
           template="../layout/template.xhtml">
           <ui:define name="body">
           <h:form id="uploadUsersForm"  enctype="multipart/form-data">
                <h:panelGrid columns="2" cellpadding="0" cellspacing="0" styleClass="form-table details" columnClasses="labels, fields">
                  <h:inputText value="#{reporte.repor}"></h:inputText>
                  <s:fileUpload id="data" 
                                data="#{inputStream}"
                                styleClass="btn-file" />         
                  <s:span styleClass="clear"></s:span>
                  <s:div styleClass="clear rt mgn-rt0">
                    <h:commandButton action="#{uploadUser.save}" value="Upload" styleClass="btn" />                 
                    </s:div>           
                </h:panelGrid>
            </h:form>
           </ui:define>
      </ui:composition>



      That might be doing wrong, I hope I can help thanks