I'm not sure if this will help or not, but here's some working
upload code I use to render attachments. Maybe you can template off this.

package forms;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.request.IUploadFile;

import utils.Log;
import attachment.Attachment;
import attachment.AttachmentData;
import data.DynaObject;
import data.HibHelper;

public class Attachments extends BasePage {
        private DynaObject fObject;
        private String fObjectClass;
        private String fObjectKey;
        private IUploadFile fData;

        public void setObjectClass(String objectClass) {
                fObjectClass = objectClass;
        }

        public IUploadFile getData() {
                return fData;
        }

        public void setData(IUploadFile data) {
                fData = data;
        }

        public void setObjectKey(String objectKey) {
                fObjectKey = objectKey;
                if (fObjectClass != null) {
                        fObject = (DynaObject)
HibHelper.getSession().get(fObjectClass,
                                        fObjectKey);
                }
        }

        public DynaObject getObject() {
                return fObject;
        }

        public void setObject(DynaObject object) {
                fObject = object;
        }

        public String getObjectClass() {
                if (fObject == null)
                        return null;
                return fObject.getClass().getCanonicalName();
        }

        public String getObjectKey() {
                if (fObject == null)
                        return null;
                return fObject.getId();
        }

        public void addNewAttachment(IRequestCycle cycle) {
                Attachment a = new Attachment();
                a.setFileName(fData.getFileName());
                a.setObjectClass(fObjectClass);
                a.setObjectId(fObjectKey);
                ByteArrayOutputStream bs = new ByteArrayOutputStream();
                InputStream is = fData.getStream();
                // now read from the input stream and write into our
outputstream
                byte[] buffer = new byte[1024];
                try {
                        while (true) {
                                int length = is.read(buffer);
                                if (length < 0) {
                                        break;
                                }
                                bs.write(buffer, 0, length);
                        }
                        is.close();
                        bs.close();
                } catch (Exception e) {
                        Log.error(e);
                }               
                AttachmentData detail = new AttachmentData();
                byte[] temp = bs.toByteArray();
                detail.setData(temp);
                a.setLength(temp.length);
                a.setDetail(detail);
                detail.setAttachment(a);
                //a.setData(bs.toByteArray());
                HibHelper.beginTransaction();
                HibHelper.getSession().save(a);
                HibHelper.getSession().save(detail);
                HibHelper.commitTransaction();
                //HibHelper.getSession().save(detail);
                //HibHelper.getSession().flush();
                // get it out of the session cache since it might be quite
large
                HibHelper.getSession().evict(detail);
        }

}

<!-- generated by Spindle, http://spindle.sourceforge.net -->

<span jwcid="border">
    <form jwcid="@Form" listener="ognl:listeners.addNewAttachment">
         <input type="text" jwcid="@Hidden" value="ognl:objectClass"/>  
         <input type="text" jwcid="@Hidden" value="ognl:objectKey"/>  
        Add New Attachment:&nbsp;
    <input jwcid="@Upload" file="ognl:data" type= "file"></input>
    <input type= "submit"value="Upload"></input>
    </form>
    <div>
        <span jwcid="attachmentList" />
    </div>
</span>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification
      PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
      "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd";>
<!-- generated by Spindle, http://spindle.sourceforge.net -->

<page-specification class="forms.Attachments">
    <property-specification name="object" type="data.DynaObject" /> 
    <component id="border" type="Border"/>
    <component id="attachmentList" type="AttachmentLister">
        <binding name="set" expression="object.attachments" />
    </component>
</page-specification>

> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Jone.hwk
> Sent: Sunday, July 31, 2005 5:20 AM
> To: [email protected]
> Subject: Cannot set thresholdSize,RepositoryPath for MultipartDecoder at
> runtime?
> 
> Hi,
> Is there a proper way to do this?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to