7 Replies Latest reply on May 15, 2007 3:05 PM by Chester Chee

    s:fileUpload throw

    Chester Chee Newbie

      Hi,

      Not sure if anyone ask about this before. I am trying to resolve an issue with <s:fileUpload>

      My components.xml is

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:drools="http://jboss.com/products/seam/drools"
       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"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd
       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.2.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd
       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-1.2.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd">
      
       <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
      
       <core:manager concurrent-request-timeout="500"
       conversation-timeout="120000"
       conversation-id-parameter="cid"
       conversation-is-long-running-parameter="clr"/>
      
       <core:managed-persistence-context name="entityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/FBISEntityManagerFactory"/>
      
       <core:ejb installed="@embeddedEjb@"/>
      
       <component class="org.jboss.seam.web.MultipartFilter">
       <property name="createTempFiles">true</property>
       <property name="maxRequestSize">5000000</property>
       </component>
      
       <drools:rule-base name="securityRules">
       <drools:rule-files>
       <value>/security.drl</value>
       </drools:rule-files>
       </drools:rule-base>
      
       <security:identity authenticate-method="#{authenticator.authenticate}"
       security-rules="#{securityRules}"/>
      
       <event type="org.jboss.seam.notLoggedIn">
       <action expression="#{redirect.captureCurrentView}"/>
       </event>
       <event type="org.jboss.seam.postAuthenticate">
       <action expression="#{redirect.returnToCapturedView}"/>
       </event>
      
       <mail:mail-session host="localhost" port="2525" username="test" password="test" />
      
       <!-- For use with jBPM pageflow or process management -->
       <!--
       <core:jbpm>
       <core:process-definitions></core:process-definitions>
       <core:pageflow-definitions></core:pageflow-definitions>
       </core:jbpm>
       -->
      
      </components>
      


      When I save the Edit form with <s:fileUpload> in it, I got the exception shown below. The file size for uploading is only 82KBytes. My maxRequestFilesize is 5MBytes. Any idea?

      Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'asset_request_form' at row 1
       at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1213)
       at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:912)
       at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
       at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
       ... 81 more
      19:05:25,746 ERROR [ExceptionFilter] uncaught exception
      


        • 1. Re: s:fileUpload throw
          Stuart Robertson Novice

          could you please attach the relevant sections of your xhtml and bean? There isn't enough info in your post to answer your question.

          • 2. Re: s:fileUpload throw
            Chester Chee Newbie

            edit.xhtml:

            <!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:a="https://ajax4jsf.dev.java.net/ajax"
             xmlns:rich="http://richfaces.ajax4jsf.org/rich"
             template="layout/template.xhtml">
            
            <ui:define name="body">
            
            <div id="taskmenu">
             <table cellpadding="0" cellspacing="0">
             <tr>
             <td><img alt="Go Back" src="img/mini-arrow-blue.gif"/><a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true">Go Back</a></td>
             </tr>
             </table>
            </div>
            
            <div id="content">
             <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
            
             <h:form id="assetType" styleClass="edit" enctype="multipart/form-data">
            
             <rich:panel>
             <f:facet name="header" rendered="#{assetTypeHome.instance.new}">New Asset Type</f:facet>
             <f:facet name="header" rendered="#{!assetTypeHome.instance.new}">Edit Asset Type</f:facet>
            
             <s:decorate id="nameDecoration" template="layout/edit.xhtml">
             <ui:define name="label">Name</ui:define>
             <h:inputText id="name"
             required="true"
             size="64"
             maxlength="64"
             value="#{assetTypeHome.instance.name}">
             <a:support event="onblur" reRender="nameDecoration"/>
             </h:inputText>
             </s:decorate>
            
             <s:decorate id="assetRequestFormDecoration" template="layout/edit.xhtml">
             <ui:define name="label">Asset Request Form</ui:define>
             <s:fileUpload id="assetRequestForm"
             data="#{assetTypeHome.instance.assetRequestForm}"
             required="true"
             contentType="application/vnd.ms-excel"/>
             </s:decorate>
            
             <s:decorate id="assetReportFormDecoration" template="layout/edit.xhtml">
             <ui:define name="label">Asset Report Form</ui:define>
             <s:fileUpload id="assetReportForm"
             data="#{assetTypeHome.instance.assetReportForm}"
             required="true"
             contentType="application/vnd.ms-excel"/>
             </s:decorate>
            
             <div style="clear:both">
             <span class="required">*</span>
             required fields
             </div>
            
             </rich:panel>
            
             <div class="actionButtons">
            
             <h:commandButton id="save"
             value="Save"
             action="#{assetTypeHome.persist}"
             disabled="#{!assetTypeHome.wired}"
             rendered="#{!assetTypeHome.managed}"/>
            
             <h:commandButton id="update"
             value="Save"
             action="#{assetTypeHome.update}"
             rendered="#{assetTypeHome.managed}"/>
            
             <h:commandButton id="delete"
             value="Delete"
             action="#{assetTypeHome.remove}"
             rendered="#{assetTypeHome.managed}"/>
            
             <s:button id="done"
             value="Done"
             propagation="end"
             view="/AssetType.xhtml"
             rendered="#{assetTypeHome.managed}"/>
            
             <s:button id="cancel"
             value="Cancel"
             propagation="end"
             view="/#{empty assetTypeFrom ? 'AssetTypeList' : assetTypeFrom}.xhtml"
             rendered="#{!assetTypeHome.managed}"/>
            
             </div>
             </h:form>
            </div>
            </ui:define>
            </ui:composition>
            


            I didn't create an action bean to do the file upload, thinking i can use "Home" bean:
            import java.util.HashSet;
            import java.util.Set;
            import javax.persistence.Basic;
            import javax.persistence.CascadeType;
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.FetchType;
            import javax.persistence.GeneratedValue;
            import javax.persistence.Id;
            import javax.persistence.Lob;
            import javax.persistence.OneToMany;
            import javax.persistence.Table;
            import javax.persistence.UniqueConstraint;
            
            import org.hibernate.annotations.Cache;
            import org.hibernate.annotations.CacheConcurrencyStrategy;
            
            import org.hibernate.validator.Length;
            import org.hibernate.validator.NotNull;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.security.Restrict;
            
            /**
             * AssetType generated by hbm2java
             */
            @Entity
            @Restrict
            @Name("assetType")
            @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
            @Table(name = "asset_type", catalog = "fbis", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
            public class AssetType implements java.io.Serializable {
            
             /**
             *
             */
             private static final long serialVersionUID = -1604122679008790458L;
             private int id;
             private String name;
             private byte[] assetRequestForm;
             private byte[] assetReportForm;
             private Set<Asset> assets = new HashSet<Asset>(0);
            
             public AssetType() {
             }
            
             public AssetType(int id, String name, byte[] assetRequestForm,
             byte[] assetReportForm) {
             this.id = id;
             this.name = name;
             this.assetRequestForm = assetRequestForm;
             this.assetReportForm = assetReportForm;
             }
             public AssetType(int id, String name, byte[] assetRequestForm,
             byte[] assetReportForm, Set<Asset> assets) {
             this.id = id;
             this.name = name;
             this.assetRequestForm = assetRequestForm;
             this.assetReportForm = assetReportForm;
             this.assets = assets;
             }
            
             @Id
             @GeneratedValue
             @Column(name = "id", unique = true, nullable = false)
             @NotNull
             public int getId() {
             return this.id;
             }
            
             public void setId(int id) {
             this.id = id;
             }
            
             @Column(name = "name", unique = true, nullable = false, length = 64)
             @NotNull
             @Length(max = 64)
             public String getName() {
             return this.name;
             }
            
             public void setName(String name) {
             this.name = name;
             }
            
             @Lob
             @Basic(fetch = FetchType.LAZY)
             @Column(name = "asset_request_form", nullable = false)
             @NotNull
             public byte[] getAssetRequestForm() {
             return this.assetRequestForm;
             }
            
             public void setAssetRequestForm(byte[] assetRequestForm) {
             this.assetRequestForm = assetRequestForm;
             }
            
             @Lob
             @Basic(fetch = FetchType.LAZY)
             @Column(name = "asset_report_form", nullable = false)
             @NotNull
             public byte[] getAssetReportForm() {
             return this.assetReportForm;
             }
            
             public void setAssetReportForm(byte[] assetReportForm) {
             this.assetReportForm = assetReportForm;
             }
             @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "assetType")
             public Set<Asset> getAssets() {
             return this.assets;
             }
            
             public void setAssets(Set<Asset> assets) {
             this.assets = assets;
             }
            
            }
            


            Thanks in advance.

            • 3. Re: s:fileUpload throw
              Stuart Robertson Novice

              Isn't it just that the uploaded file is too big for the column? You might want to put some debug in the byte [] setter to check the size, and also specify the column size.

              • 4. Re: s:fileUpload throw
                Chester Chee Newbie

                In the database, these two "form" fields are blog data type. My impression is this is binary data for any size, is that correct assumption? Thanks in advance.

                • 5. Re: s:fileUpload throw
                  Chester Chee Newbie

                  sorry.. typo. blog should be blob

                  • 6. Re: s:fileUpload throw
                    Shane Bryzak Master

                    I know that some databases have different sizes for blob fields, MySQL being one example, with a standard blob size of 64K. You could confirm this by trying to upload a smaller file, and if that works then change the blob field type to something larger.

                    • 7. [Resolved] Re: s:fileUpload throw
                      Chester Chee Newbie

                      Thanks. That was the issue. Greatly appreciated.