9 Replies Latest reply on Jun 11, 2010 8:06 AM by Gerrit Abma

    seam fileupload

    mario neal Newbie

      hello to all..
      i'm trying since 2 days to config the seam file uplpoad...but it isnt working..
      so my question is.. what for configurations should i do?? if i press the upload button i wil reach always to the else part in the java class..



      THE JAVA CLASS
      package ch.spectromedia.util;

      import static org.jboss.seam.ScopeType.CONVERSATION;

      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;

      @Scope(CONVERSATION)
      @Name("register")
      public class RegisterAction {

              private byte[] picture;

              public void uploadPicture() {
                      if (picture != null && picture.length > 0) {
                              System.out.println("Die grösse des Bildes" + picture.length);
                      }
                      else{
                              System.out.println("der else fall ist eingetroffen..wieso auch immer");
                      }

              }

              public byte[] getPicture() {
                      return picture;
              }

              public void setPicture(byte[] picture) {
                      this.picture = picture;
              }
      }





      THE JSF PART..
      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <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:rich="http://richfaces.org/rich"
              xmlns:a4j="http://richfaces.org/a4j"
              template="/layout/mee_template.xhtml">
              <ui:define name="body">
                      <h:form styleClass="register" enctype="multipart/form-data">
                                      <div class="formRow"><h:outputLabel for="picture">Member photo</h:outputLabel>
                                      <s:fileUpload id="picture" data="#{register.picture}"
                                              accept="image/jpg" />
                                      <div class="validationError"><h:message for="picture" /></div>
                                      </div>
                              <div class="buttons"><h:commandButton value="Upload"
                                      action="#{register.uploadPicture}" styleClass="registerButton" /></div>

                      </h:form>
              </ui:define>
      </ui:composition>

        • 1. Re: seam fileupload
          mario neal Newbie


          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <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:rich="http://richfaces.org/rich"
               xmlns:a4j="http://richfaces.org/a4j"
               template="/layout/mee_template.xhtml">
               <ui:define name="body">
                    <h:form styleClass="register" enctype="multipart/form-data">
                              <div class="formRow"><h:outputLabel for="picture">Member photo</h:outputLabel>
                              <s:fileUpload id="picture" data="#{register.picture}"
                                   accept="image/jpg" />
                              <div class="validationError"><h:message for="picture" /></div>
                              </div>
                         <div class="buttons"><h:commandButton value="Upload"
                              action="#{register.uploadPicture}" styleClass="registerButton" /></div>
          
                    </h:form>
               </ui:define>
          </ui:composition>





          package ch.spectromedia.util;
          
          import static org.jboss.seam.ScopeType.CONVERSATION;
          
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          
          @Scope(CONVERSATION)
          @Name("register")
          public class RegisterAction {
          
               private byte[] picture;
          
               public void uploadPicture() {
                    if(picture == null){
                         System.out.println("picture is null!!");
                    }
                    if (picture != null && picture.length > 0) {
                         System.out.println("Die grösse des Bildes" + picture.length);
                    }
                    else{
                         System.out.println("der else fall ist eingetroffen..wieso auch immer");
                    }
          
               }
          
               public byte[] getPicture() {
                    return picture;
               }
          
               public void setPicture(byte[] picture) {
                    this.picture = picture;
               }
          }





          • 2. Re: seam fileupload
            Leo van den berg Master

            Have you configured the Seam Filter (org.jboss.seam.servlet.SeamFilter) in web.xml ??


            • 3. Re: seam fileupload
              mario neal Newbie


                  <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>
              
                  



              is that enough? if yes i have..


              • 4. Re: seam fileupload
                Leo van den berg Master

                Don't see any difference with our approach, we use the ajax-buttons and a Home conmponent.


                Should work,

                • 5. Re: seam fileupload
                  mario neal Newbie

                  whatabout the component.xml.. should i write there anything to??

                  • 6. Re: seam fileupload
                    Leo van den berg Master

                    You can ad property settings in components for the specific filter, but thats for size etc.


                    • 7. Re: seam fileupload
                      Binesh Gummadi Novice

                      I would debug by adding this to components.xml and see if it is creating files in /tmp directory.


                      <component class="org.jboss.seam.web.MultipartFilter">
                        <property name="createTempFiles">true</property>
                        <property name="maxRequestSize">1000000</property>
                      </component>
                      




                      • 8. Re: seam fileupload
                        Gerrit Abma Newbie

                        Hi,


                        Did you ever find a fix for this problem?


                        I have a similar problem. I noticed that the tag


                        <h:form id="someid" enctype="multipart/form-data">



                        is getting rendered as form, but without the enctype="multipart/form-data" part. This results in not sending the file. I don't know yet what causes this.


                        Any ideas?

                        • 9. Re: seam fileupload
                          Gerrit Abma Newbie

                          Found the problem that caused it for me: having both jsf-api and myfaces-api on the classpath. Removing the myfaces-api solved it.