4 Replies Latest reply on Jul 26, 2007 7:15 PM by rtrancoso

    s:fileUpload woes

    chrismalan

      s:fileUpload doesn't work for me. Here is what I have: Seam 1.2.1.GA, JBoss-4.2.0. I use xhtml, not jsp's.

      In the ear I have jboss-seam.jar and in WEB-INF/lib jboss-seam-ui.jar, jboss-seam-debug.jar and jsf-facelets.jar.

      This is what is in web.xml:

      <listener>
       <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
      </listener>
      
      <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>/*</url-pattern>
      </filter-mapping>
      


      This is the relevant part of the xhtml file:
      <h:form enctype="multipart/formdata">
       <fieldset>
       <legend>Add an Image to <h:outputText value="#{hotelSessionBean.hotel.name}" /></legend>
       <div>
       <h:outputLabel for="hotelimage">Image File to Load</h:outputLabel><br />
       <s:fileUpload id="hotelimage" data="#{hotelSessionBean.imageData}" contentType="#{hotelSessionBean.contentType}" fileName="#{hotelSessionBean.filename}" />
       </div>
       <div class="buttonBox">
       <h:commandButton action="#{hotelSessionBean.addImage()}" value="Add an Image" class="button" />
       </div>
       </fieldset>
      </h:form>
      


      This is the relevant part of hotelSessionBean:
      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("hotelSessionBean")
      public class HotelSessionBean implements HotelSession {
      
       @In
       Identity identity;
      
       @PersistenceContext
       EntityManager em;
      
       private Hotel hotel;
       private String contentType, filename, description;
       private byte[] imageData;
      


      When I test in hotelSessionBean.addImage() to see if the values (contentType, filename, imageData) arrived in the hotelSessionBean after clicking the Add an Image button, all those values are null.

      When these values return null, the method returns with an error message I created. So, no exceptions are thrown. Before I tested the exeptions stated that one could not persist an Image with null values where the database stipulatd non-null values.

      On logging in and going to the page from where to upload the image, I get this:
      INFO [Lifecycle] starting up: org.jboss.seam.security.identity
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jboss-seam-ui.jar!/META-INF/seam-ui.taglib.xml
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-core.taglib.xml
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-html.taglib.xml
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-core.taglib.xml
      ERROR [STDERR] 18/07/2007 14:38:08 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
      INFO: Added Library from: jar:file:/C:/JBoss/jboss-4.2.0.GA/server/default/tmp/deploy/tmp50450bookings.ear-contents/bookings-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-ui.taglib.xml
      *** logging in up to here
      INFO [STDOUT] Hibernate: select principal0_.username as username7_, principal0_.name as name7_, principal0_.password as password7_, principal0_.hotel_hotelID as hotel7_7_, principal0_.email as email7_, principal0_.surname as surname7_, principal0_.created as created7_ from Principal principal0_ where principal0_.username=? and principal0_.password=?
      INFO [STDOUT] Hibernate: select hotel0_.hotelID as hotelID5_1_, hotel0_.name as name5_1_, hotel0_.state as state5_1_, hotel0_.country as country5_1_, hotel0_.description as descript4_5_1_, hotel0_.city as city5_1_, hotel0_.stars as stars5_1_, hotel0_.street as street5_1_, hotel0_.suburb as suburb5_1_, country1_.ID as ID2_0_, country1_.country as country2_0_ from Hotel hotel0_ inner join Country country1_ on hotel0_.country=country1_.ID where hotel0_.hotelID=?
      INFO [STDOUT] Hibernate: select principalr0_.ID as ID8_, principalr0_.principal as principal8_, principalr0_.user_role as user3_8_ from PrincipalRole principalr0_ where principalr0_.principal=?
      INFO [STDOUT] Hibernate: select role0_.name as name9_0_, role0_.description as descript2_9_0_ from Role role0_ where role0_.name=?
      INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      


      Note that the page find the right hotel for the logged in user to upload the image to the right hotel.

      Where is my mistake?

      Thanks,


        • 1. Re: s:fileUpload woes
          dahm

          Hi,

          Did you add the Multipart-Filter in web.xml?

           <filter>
           <filter-name>Seam Multipart Filter</filter-name>
           <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
           </filter>
          
           <filter-mapping>
           <filter-name>Seam Multipart Filter</filter-name>
           <url-pattern>*.seam</url-pattern>
           </filter-mapping>
          


          Cheers
          Markus

          • 2. Re: s:fileUpload woes
            chrismalan

            Hi Markus,

            Yes, it's there. Only, I called it Seam Filter and not Seam Multipart Filter.
            I changed the name, moved it up in web.xml - no luck.

            A simple text input get its value propagated to the session bean. The file upload input is totally invisible to the application.

            As far as I'm aware, I did everything by the book. Where can the problem be?

            • 3. Re: s:fileUpload woes
              chrismalan

              Got it. formdata should be form-data.

              • 4. Re: s:fileUpload woes
                rtrancoso

                i found this

                http://shrubbery.mynetgear.net/wiki/Facelets_'loadImplicit'_error

                One annoying thing about using Facelets with SEAM/EJB3/JBoss is that there are some strange 'ERROR' log messages that happen when the first page is hit. They look something like this:

                07:38:26,843 ERROR \[STDERR\] Nov 29, 2006 7:38:26 AM com.sun.facelets.compiler.TagLibraryConfig loadImplicit
                INFO: Added Library from: jar:file:/C:/java/jboss-4.0.5.GA-ejb3/server/default/./tmp/deploy/tmp64384starter1.ear-contents/webapp-exp.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-ui.taglib.xml
                So, I've finally figured out what this means. Basically, the Facelets compiler is emitting the message to System.err, which JBoss's Log4J setup interprets as an error level log message. I think that's a reasonable assumption to make with Log4J.

                If java.util.logging were a pet dog I'd say: Bad logging! Bad! Nnno!

                The folks at Sun should know better than to write to System.err, especially if the message is not an error. Perhaps the JDK logging can be tweaked to make this work better, but still... highly annoying.

                [edit] Solution #1
                Ignore the messages. They are only errors because ConsoleHandler writes log messages to System.err (dodgy) and the JBoss logging framework interprets them as errors, redirecting the messages as ERROR level (understandable).

                [edit] Solution #2
                Use a different logging handler by using a different java.util.logging (a.k.a. JULI) configuration.

                [edit] Solution #3
                Experimental - Use a ContextListener to reconfigure JULI to send logging messages to Log4J. :)

                Retrieved from "http://shrubbery.mynetgear.net/wiki/Facelets_%27loadImplicit%27_error"