Re: Have any DynamicByteArrayResource sample?

2008-04-07 Thread rosen jiang

well, I have some idea:

ByteArrayOutputStream baos = new ByteArrayOutputStream();

.
.
.
add(new Link(download) {
public void onClick() {
 WebResponse response = (WebResponse) getResponse();
 response.setHeader(Content-Disposition,
attachment;filename= + aaa.xls);

response.setContentType(application/x-msdownload);
 response.getOutputStream().write(baos.toByteArray());
 baos.flush();
 baos.close();
 }});

It's work! very easy, like a Servlet, but above codes need some
try-catch-finally block.


Nino.Martinez wrote:
 
 take a look at DynamicImageResource.. It should give some hints.
 
 
 
 rosen jiang wrote:
 Hi all,

 I want use DynamicByteArrayResource class download Excel(ByteArray
 Resource  
 not File) from jexcelapi.
 Does DynamicByteArrayResource class fit for me?

 thx!
 best regards,
 osen jiang
   
 
 -- 
 -Wicket for love
 
 Nino Martinez Wael
 Java Specialist @ Jayway DK
 http://www.jayway.dk
 +45 2936 7684
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Have-any-DynamicByteArrayResource-sample--tp16525712p16537476.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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



Re: Have any DynamicByteArrayResource sample?

2008-04-07 Thread Nino Saturnino Martinez Vazquez Wael

true, this is how id did once too:)

rosen jiang wrote:

well, I have some idea:

ByteArrayOutputStream baos = new ByteArrayOutputStream();

.
.
.
add(new Link(download) {
public void onClick() {
 WebResponse response = (WebResponse) getResponse();
 response.setHeader(Content-Disposition,
attachment;filename= + aaa.xls);

response.setContentType(application/x-msdownload);

 response.getOutputStream().write(baos.toByteArray());
 baos.flush();
 baos.close();
 }});

It's work! very easy, like a Servlet, but above codes need some
try-catch-finally block.


Nino.Martinez wrote:
  

take a look at DynamicImageResource.. It should give some hints.



rosen jiang wrote:


Hi all,

I want use DynamicByteArrayResource class download Excel(ByteArray
Resource  
not File) from jexcelapi.

Does DynamicByteArrayResource class fit for me?

thx!
best regards,
osen jiang
  
  

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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






  


--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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



Re: Have any DynamicByteArrayResource sample?

2008-04-07 Thread John Krasnay
On Mon, Apr 07, 2008 at 07:32:48AM -0700, rosen jiang wrote:
 
 well, I have some idea:
 
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
 .
 .
 .
 add(new Link(download) {
 public void onClick() {
WebResponse response = (WebResponse) getResponse();
  response.setHeader(Content-Disposition,
 attachment;filename= + aaa.xls);
 
 response.setContentType(application/x-msdownload);
response.getOutputStream().write(baos.toByteArray());
baos.flush();
  baos.close();
  }});
 
 It's work! very easy, like a Servlet, but above codes need some
 try-catch-finally block.
 

Hi Rosen,

The problem with your code is that your BAOS is serialized with your
page, which means that your entire report is using up space in your
session, even if the user never clicks the link.

Here's some code from my application that uses Wicket's
AbstractResourceStreamWriter, which was mentioned on this list a few
days ago:

@Override
public void onClick() {
final ReportGenerator generator = getReportGenerator();

IResourceStream resourceStream = new
AbstractResourceStreamWriter() {
public void write(OutputStream output) {
try {
generator.generate(output, columns, dataProvider);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String getContentType() {
return generator.getContentType();
}

};

getRequestCycle().setRequestTarget(new
ResourceStreamRequestTarget(resourceStream).setFileName(getFileName()));
}

ReportGenerator is my own abstraction for generating the report. Note
that the bytes are generated only when the link is clicked, and they are
streamed directly to the client without being stored in an intermediate
byte array.

Hope this helps.

jk

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



Re: Have any DynamicByteArrayResource sample?

2008-04-06 Thread Nino Saturnino Martinez Vazquez Wael

take a look at DynamicImageResource.. It should give some hints.



rosen jiang wrote:

Hi all,

I want use DynamicByteArrayResource class download Excel(ByteArray Resource  
not File) from jexcelapi.

Does DynamicByteArrayResource class fit for me?

thx!
best regards,
osen jiang
  


--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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



Have any DynamicByteArrayResource sample?

2008-04-06 Thread rosen jiang

Hi all,

I want use DynamicByteArrayResource class download Excel(ByteArray Resource  
not File) from jexcelapi.
Does DynamicByteArrayResource class fit for me?

thx!
best regards,
osen jiang
-- 
View this message in context: 
http://www.nabble.com/Have-any-DynamicByteArrayResource-sample--tp16525712p16525712.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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