11 Replies Latest reply on Jun 4, 2009 2:46 PM by Gaurav Chauhan

    Uploading Excel sheet in data base using seam

    Gaurav Chauhan Newbie

      Hi,
      all i am trying to upload excel sheet in database using seam,( using the examples for uploading the files)
      but i am getting the file object as null on server side.
      can any one help in providing the code or example  on how to upload the excel sheet.

        • 1. Re: Uploading Excel sheet in data base using seam
          Robert Morse Apprentice

          It would help if you could post how you're currently trying to do this.  Are you using s:fileUpload or something else? 

          • 2. Re: Uploading Excel sheet in data base using seam
            Gaurav Chauhan Newbie
            //this is my xhtml page which i am using for upload
            //XHTML

            <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.ajax4jsf.org/rich"
              xmlns:a="https://ajax4jsf.dev.java.net/ajax">


            <rich:simpleTogglePanel switchType="client"
                            label="Upload">
            <h:panelGrid width="75%">
            <h:panelGroup id="Upload">
            <h:form enctype="multipart/form-data">
            <table border="0">
            <tbody>
            <tr>
            <th>
               <h:outputText value="UploadExcel :" />                  
            </th>
            <th>
              <s:fileUpload data="${massDataUploadService.data}"
                  accept="${massDataUploadService.accept}"
                  contentType="${massDataUploadService.contentType}"
                  fileName="${massDataUploadService.name}"
                  fileSize="${massDataUploadService.size}" size="40"
                  maxlength="80" />
            </th>
            </tr>
            <tr>
            <td>
            </td>
            <td>
            <a:commandButton value="Upload" action="#{massDataUploadService.upload}"/>                   
            <rich:spacer width="10" />
            <a:commandButton value="Cancel" type="reset"/>
            </td>
            </tr>
            </tbody>
            </table>
            </h:form>
            </h:panelGroup>
            </h:panelGrid>           
            </rich:simpleTogglePanel>
            </ui:composition>
            • 3. Re: Uploading Excel sheet in data base using seam
              Gaurav Chauhan Newbie
              // I am just trying print the values i am getting
              // but i am getting all the values as null

              import org.jboss.seam.ScopeType;
              import org.jboss.seam.annotations.Logger;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Scope;
              import org.jboss.seam.log.Log;

              @Scope(ScopeType.SESSION)
              @Name("massDataUploadService")
              public class MassDataUploadAction {
               
                @Logger
                Log log;
               
                private static final String accept = "text/plain,text/xml,application/xml,application/vnd.ms-excel";
                   private byte[] data;
                   private String contentType;   
                   private String name;   
                   private String title;   
                   private int size;
                   
                   
                   public byte[] getData() {
                        return data;
                   }
                   public void setData(byte[] data) {
                        this.data = data;
                   }
                   public String getContentType() {
                        return contentType;
                   }
                   public void setContentType(String contentType) {
                        this.contentType = contentType;
                   }
                   public String getName() {
                        return name;
                   }
                   public void setName(String name) {
                        this.name = name;
                   }
                   public String getTitle() {
                        return title;
                   }
                   public void setTitle(String title) {
                        this.title = title;
                   }
                   public int getSize() {
                        return size;
                   }
                   public void setSize(int size) {
                        this.size = size;
                   }
                   
                   

                public void upload(){
                     System.out.println("in upload---name---->  "+name);
                     System.out.println("in upload---contentType---->  "+contentType);
                     System.out.println("in upload---size---->  "+size);
                     System.out.println("in upload---title---->  "+title);

                      }


                public String getAccept() {
                  return accept;
                }
              }

              • 4. Re: Uploading Excel sheet in data base using seam
                Gaurav Chauhan Newbie
                // components.xml

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

                // web.xml

                    <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>
                • 5. Re: Uploading Excel sheet in data base using seam
                  Robert Morse Apprentice

                  The syntax for s:fileUpload looks correct.  I've never tried embedding it within a table, but I noticed that you have:
                  xmlns:rich="http://richfaces.ajax4jsf.org/rich


                  In my stuff that works just fine, I have:
                  xmlns:rich="http://richfaces.org/rich"


                  Version of Seam / Richfaces you're using?

                  • 6. Re: Uploading Excel sheet in data base using seam
                    Gaurav Chauhan Newbie

                    hey Robert thanks for your quick reply..
                    it tried it and even removed the table but still it didnt work for me
                    still every thing is comming null


                    my seam version is 2.1.0


                    can you please post your code
                    and also do i need any specific jar for uploading

                    • 7. Re: Uploading Excel sheet in data base using seam
                      Gaurav Chauhan Newbie

                      Seam Version is Seam 2.1.0.SP1
                      RichFaces version is 3.2.2.GA

                      • 8. Re: Uploading Excel sheet in data base using seam
                        Robert Morse Apprentice

                        You're sure that the jboss-seam-pdf.jar file is in the correct place?  In my EAR deployment, I have it in the war (WEB-INF/lib).

                        • 9. Re: Uploading Excel sheet in data base using seam
                          Robert Morse Apprentice

                          Ignore my last comment.  I was thinking of a different thread.

                          • 10. Re: Uploading Excel sheet in data base using seam
                            Robert Morse Apprentice

                            Here's an example of what I use to upload an image file.  Uploading something like Excel is identical.




                            <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:a="https://ajax4jsf.dev.java.net/ajax"
                                 xmlns:a4j="http://richfaces.org/a4j"
                                 xmlns:rich="http://richfaces.org/rich">
                            





                                           <h:form styleClass="imageUploadForm" enctype="multipart/form-data">
                            
                                                <a:region>
                                                     <s:decorate id="imageUploadDecoration"
                                                          template="includes/formFieldDecorate.xhtml">
                                                          <ui:define name="label">Image</ui:define>
                                                          <s:fileUpload id="imageUpload" fileName="#{image.fileName}"
                                                               data="#{image.content}" contentType="#{image.contentType}"
                                                               acceptedTypes="jpg,png,tif" size="80" tabindex="10" required="true" />
                                                     </s:decorate>
                                                </a:region>





                            image is managed via EntityHome, and it has simple getters / setters for the properties.   And that's it.  Works for any kind of file.



                            • 11. Re: Uploading Excel sheet in data base using seam
                              Gaurav Chauhan Newbie

                              No results
                              i am still getting the same null values.
                              i had even tried to use rich faces to upload file but there also
                              i am getting all tha values as null
                              not able to figure out why i am not able to upload file and the whole world can upload the same...:(