Thanks for suggestion !

I tried ResourceLink combine with DynamicByteArrayResource:

 resource =  new DynamicByteArrayResource() {
       public String getContentType() {
              return pdfType;
       }
      protected byte[] getData() {
              return myData;
       }
} ;

add(new ResourceLink("download", resource) );

This works too, however, I have no chance to tweak the response header to make download
popup a window:

   WebResponse response = (WebResponse) getResponse();
   response.setHeader("Content-Disposition", "attachment;filename=myfile.pdf");

Is there any hook in ResourceLink to do this ? I tried onClick() but it doesn't work.


On 2/15/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
When do you generate that byte[] is it already there? when you construct the link?
Then i would replace the new Link() with new ResourceLink(xx,new ByteArrayResourceStream())
else yes use youre DynamicByteArrayResource.
But i still would use the ResourceLink not implement that resource streaming youreself in the onclick.

johan




On 2/15/06, Ingram Chen <[EMAIL PROTECTED]> wrote:
I got answer:

new Link("download") {
    public void onClick() {
        DynamicByteArrayResource dynamicByteArrayResource = new DynamicByteArrayResource() {....};

        getRequestCycle().setRequestTarget(
            new ResourceStreamRequestTarget(
                    dynamicByteArrayResource
                            .getResourceStream(), contentType));

        WebResponse response = (WebResponse) getResponse();

        response.setHeader("Content-Disposition",
            "attachment;filename=" + "myfile.pdf");

        response.setContentType(contentType);
    }
};

Hope this is correct way to deal with dynamic resouce.

On 2/15/06, Ingram Chen < [EMAIL PROTECTED]> wrote:
Dear all,

    I would like to download iText pdf document via Link component:

   new Link("download") {
        public void onClick() {
                  WebResponse response = (WebResponse) getResponse();
                  response.setHeader(....);
                  response.setContentType(....);
                  OutputStream outputStream = response.getOutputStream();
                  outputStream.write(myDataBytes);
                  outputStream.flush();
        }
   }

   But this does not work. I search wiki but there is no information how to do
this. Could someone give me some suggestions ?

--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen



--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen




--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to