Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-26 Thread BrianWilliams
Not only did this work before, it has worked in every other web technology I've 
tried.  Can anyone on the Wicket team explain how Response handling changed in 
1.5?  I am hoping there is a single line fix, like response.clearBuffer(), that 
will make my existing code work as it always has, rather than refactor this 
with brand new code.
 
Thank you very much.
 


 From: Sven Meier [via Apache Wicket] ml-node+s1842946n466064...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Friday, August 2, 2013 1:17 AM
Subject: Re: Generating spreadsheet to send to Client fails in 1.6
  


Hi, 

I don't know how this worked for you in 1.4.x. 

But if you're just writing something into the response, how should 
Wicket know that it has to stop processing the request? 


Sven 

On 08/02/2013 04:24 AM, BrianWilliams wrote: 




- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 






 
If you reply to this email, your message will be added to the discussion below:
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660643.html
  
To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click here.
NAML



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4661083.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-26 Thread Sven Meier
Please create a quickstart for Wicket 1.4.x so we can see how your 
solution worked.


Thanks
Sven

On 08/26/2013 04:49 PM, BrianWilliams wrote:

Not only did this work before, it has worked in every other web technology I've 
tried.  Can anyone on the Wicket team explain how Response handling changed in 
1.5?  I am hoping there is a single line fix, like response.clearBuffer(), that 
will make my existing code work as it always has, rather than refactor this 
with brand new code.
  
Thank you very much.
  



  From: Sven Meier [via Apache Wicket] 
ml-node+s1842946n466064...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com
Sent: Friday, August 2, 2013 1:17 AM
Subject: Re: Generating spreadsheet to send to Client fails in 1.6
   



Hi,

I don't know how this worked for you in 1.4.x.

But if you're just writing something into the response, how should
Wicket know that it has to stop processing the request?


Sven

On 08/02/2013 04:24 AM, BrianWilliams wrote:




-
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]






  
If you reply to this email, your message will be added to the discussion below:

http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660643.html
To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click here.
NAML



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4661083.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-02 Thread Sven Meier

Hi,

I don't know how this worked for you in 1.4.x.

But if you're just writing something into the response, how should 
Wicket know that it has to stop processing the request?



Sven

On 08/02/2013 04:24 AM, BrianWilliams wrote:

Thank you but, did you see my original code?  It's 1/2 as long as the import 
section in your link.   I would like to simply write to the response, as I have 
in every other web technology (from Servlets and JSPs to Struts, JSF and .NET), 
AND Wicket prior to 1.5.
  
Perhaps somebody from the Wicket team can explain why this valid strategy no longer works.  Did you really break this Response behavior?



  From: Martin Grigorov-4 [via Apache Wicket] 
ml-node+s1842946n4660604...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com
Sent: Thursday, August 1, 2013 12:52 AM
Subject: Re: Generating spreadsheet to send to Client fails in 1.6
   



Hi,

See
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java?source=cc#L167
for
a simple example.


On Thu, Aug 1, 2013 at 5:33 AM, BrianWilliams
[hidden email]wrote:


  





  
If you reply to this email, your message will be added to the discussion below: http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660604.html

To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click here.
NAML



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660638.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-02 Thread BrianWilliams
It simply redisplays the page and gives me the option to open or save the 
spreadsheet.  When I choose open, it's in another window so what I write 
directly to the response looks like an attachment to the browser.
 


 From: Sven Meier [via Apache Wicket] ml-node+s1842946n466064...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Friday, August 2, 2013 1:17 AM
Subject: Re: Generating spreadsheet to send to Client fails in 1.6
  


Hi, 

I don't know how this worked for you in 1.4.x. 

But if you're just writing something into the response, how should 
Wicket know that it has to stop processing the request? 


Sven 

On 08/02/2013 04:24 AM, BrianWilliams wrote: 




- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 






 
If you reply to this email, your message will be added to the discussion below:
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660643.html
  
To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click here.
NAML



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660659.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-01 Thread Martin Grigorov
Hi,

See
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java?source=cc#L167
for
a simple example.


On Thu, Aug 1, 2013 at 5:33 AM, BrianWilliams
brianwilliams33...@yahoo.comwrote:

 Thank you again Paul.  I'll look at scheduleRequestHandlerAfterCurrent and
 compare it.

 And yes, you are right that IResourceStream is straightforward, but again
 I am blown away that something that worked perfectly pre6.x now requires a
 different strategy.  And no, I am not setting cookies or buffering, just
 generating and sending that spreadsheet down.
 Cheers.


 
  From: Paul Bors [via Apache Wicket] 
 ml-node+s1842946n4660599...@n4.nabble.com
 To: BrianWilliams brianwilliams33...@yahoo.com
 Sent: Wednesday, July 31, 2013 4:24 PM
 Subject: RE: Generating spreadsheet to send to Client fails in 1.6



 Well... Component.getResponse() calls getRequestCycle().getResponse() and
 you're then you're casting that Response object to a WebResponse and change
 it in the middle of wicket's processing it.

 Is simple to schedule your resource outside of wicket's normal flow right?
 Hence getRequestCycle().scheduleRequestHandlerAfterCurrent() which
 schedules the request handler to be executed after the current one works
 much better for downloading a resource right?

 If you don't like that explanation look over the JavaDoc of the
 WebResponse and its API and compare it with that of the IResourceStream.

 You have to ask yourself, are you going to set any cookies or a buffer
 along with your spreadsheet download? :)

 ~ Thank you,
   Paul Bors


 -Original Message-
 From: BrianWilliams [mailto:[hidden email]]
 Sent: Wednesday, July 31, 2013 4:43 PM
 To: [hidden email]
 Subject: Re: Generating spreadsheet to send to Client fails in 1.6

 Thank you Paul.  I appreciate the advice.  Regarding your suggestion to
 use IResourceStream, I wonder what the problem is with writing to the web
 response?  Is this simply something that is no longer supported in 6.x,
 even though it worked perfectly in 4.x?

 I'd prefer to simply fix whatever is wrong with my current code


 
  From: Paul Bors [via Apache Wicket] [hidden email]
 To: BrianWilliams [hidden email]
 Sent: Wednesday, July 31, 2013 11:40 AM
 Subject: RE: Generating spreadsheet to send to Client fails in 1.6



 I think you should also upgrade your Apache POI version and switch to .xlsx
 since the older format has a limit of about 65K records. Outside of that I
 suggest you use an IResourceStream instead of writing to your web response.

 Personally I use csv comma delimited since I don't do any magic beside
 export those records to be viewed in Excel, edited and then imported back
 via the webapp.

 In any event this is how I do it via Wicket 6.x:

 @Override
 protected void onClick() {
 IResourceStream csvStream = new
 CsvResourceStream(service.exportAll(getSession().getLocale()));
 String fileNameKey = ...;
 getRequestCycle().scheduleRequestHandlerAfterCurrent(
 new

 ResourceStreamRequestHandler(csvStream).setFileName(ResourceKeyHelper.resour
 ceValue(fileNameKey) + .csv)
 );
 }

 public class CsvResourceStream extends AbstractResourceStream {
 private static final long serialVersionUID = 1L;

 public CsvResourceStream(ByteArrayOutputStream outputStream) {
 super(outputStream.toByteArray());
 IOUtils.closeQuietly(outputStream);
 }

 @Override
 public String getContentType() {
 return new StringBuilder()
 .append(text/comma-separated-values, )
 .append(text/csv, )
 .append(application/csv, )
 .append(application/excel)
 .toString();
 }
 }

 You can switch it to your HSSFWorkbook and grab its byte content.

 -Original Message-
 From: BrianWilliams [mailto:[hidden email]]
 Sent: Wednesday, July 31, 2013 1:14 PM
 To: [hidden email]
 Subject: Generating spreadsheet to send to Client fails in 1.6

 Hello,

 I had code in Wicket 1.x that worked perfectly to dynamically generate a
 spreadsheet and send it to the user.  I had to rewrite it for the new
 Response classes in 1.6:

 public void generateExcel(String filename, ListList? extends
 Object dataList) {
 HSSFWorkbook myWorkBook = new HSSFWorkbook();
 HSSFSheet mySheet = myWorkBook.createSheet();
 ... (generate sheet from dataList using HSSFSheet methods)
 WebResponse response = (WebResponse)getResponse();
 webResponse.setContentType(application/vnd.ms-excel);
 webResponse.setAttachmentHeader(filename + .xls);
 OutputStream out = webResponse.getOutputStream();
 myWorkBook.write(out);
 out.close();
 }

 The sheet is still being populated as I need, and the client is asked to
 open or save the filename.xls file (as expected).

 The problem with 1.6 is: the current page is sent 

Re: Generating spreadsheet to send to Client fails in 1.6

2013-08-01 Thread BrianWilliams
Thank you but, did you see my original code?  It's 1/2 as long as the import 
section in your link.   I would like to simply write to the response, as I have 
in every other web technology (from Servlets and JSPs to Struts, JSF and .NET), 
AND Wicket prior to 1.5. 
 
Perhaps somebody from the Wicket team can explain why this valid strategy no 
longer works.  Did you really break this Response behavior? 


 From: Martin Grigorov-4 [via Apache Wicket] 
ml-node+s1842946n4660604...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Thursday, August 1, 2013 12:52 AM
Subject: Re: Generating spreadsheet to send to Client fails in 1.6
  


Hi, 

See 
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/link/DownloadLink.java?source=cc#L167
for 
a simple example. 


On Thu, Aug 1, 2013 at 5:33 AM, BrianWilliams 
[hidden email]wrote: 


 




 
If you reply to this email, your message will be added to the discussion below: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660604.html
  
To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click here.
NAML



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660638.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Generating spreadsheet to send to Client fails in 1.6

2013-07-31 Thread BrianWilliams
Hello,

I had code in Wicket 1.x that worked perfectly to dynamically generate a
spreadsheet and send it to the user.  I had to rewrite it for the new
Response classes in 1.6:

public void generateExcel(String filename, ListListlt;? extends
Object dataList) {
HSSFWorkbook myWorkBook = new HSSFWorkbook();
HSSFSheet mySheet = myWorkBook.createSheet();
... (generate sheet from dataList using HSSFSheet methods)
WebResponse response = (WebResponse)getResponse();
webResponse.setContentType(application/vnd.ms-excel);
webResponse.setAttachmentHeader(filename + .xls);
OutputStream out = webResponse.getOutputStream();
myWorkBook.write(out);
out.close();
}

The sheet is still being populated as I need, and the client is asked to
open or save the filename.xls file (as expected).

The problem with 1.6 is: the current page is sent rather than the sheet I've
built.   My .xls viewer complains that the file is not in the correct format
and, when I display it anyway, contains the original Wicket page, head, css,
javascript and all.

The same problems happens when generating xml from the same data list:

WebResponse response = (WebResponse)getResponse();
response.setContentType(application/xml);
response.setAttachmentHeader(filename + .xml);
XMLStreamWriter out =
XMLOutputFactory.newInstance().createXMLStreamWriter(response.getOutputStream());

out.writeStartDocument();
... (generate XML document from dataList)
out.writeEndDocument();
out.close();

This also sends the original HTML page to the client. 

Both methods worked perfectly before I migrated to Wicket 1.6, but now the
Response (returned by getResponse()) seems to behave differently.  Any
ideas?  Thank you very much.



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Generating spreadsheet to send to Client fails in 1.6

2013-07-31 Thread Paul Bors
I think you should also upgrade your Apache POI version and switch to .xlsx
since the older format has a limit of about 65K records. Outside of that I
suggest you use an IResourceStream instead of writing to your web response.

Personally I use csv comma delimited since I don't do any magic beside
export those records to be viewed in Excel, edited and then imported back
via the webapp.

In any event this is how I do it via Wicket 6.x:

@Override
protected void onClick() {
IResourceStream csvStream = new
CsvResourceStream(service.exportAll(getSession().getLocale()));
String fileNameKey = ...;
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new
ResourceStreamRequestHandler(csvStream).setFileName(ResourceKeyHelper.resour
ceValue(fileNameKey) + .csv)
);
}

public class CsvResourceStream extends AbstractResourceStream {
private static final long serialVersionUID = 1L;

public CsvResourceStream(ByteArrayOutputStream outputStream) {
super(outputStream.toByteArray());
IOUtils.closeQuietly(outputStream);
}

@Override
public String getContentType() {
return new StringBuilder()
.append(text/comma-separated-values, )
.append(text/csv, )
.append(application/csv, )
.append(application/excel)
.toString();
}
}

You can switch it to your HSSFWorkbook and grab its byte content.

-Original Message-
From: BrianWilliams [mailto:brianwilliams33...@yahoo.com] 
Sent: Wednesday, July 31, 2013 1:14 PM
To: users@wicket.apache.org
Subject: Generating spreadsheet to send to Client fails in 1.6

Hello,

I had code in Wicket 1.x that worked perfectly to dynamically generate a
spreadsheet and send it to the user.  I had to rewrite it for the new
Response classes in 1.6:

public void generateExcel(String filename, ListListlt;? extends
Object dataList) {
HSSFWorkbook myWorkBook = new HSSFWorkbook();
HSSFSheet mySheet = myWorkBook.createSheet();
... (generate sheet from dataList using HSSFSheet methods)
WebResponse response = (WebResponse)getResponse();
webResponse.setContentType(application/vnd.ms-excel);
webResponse.setAttachmentHeader(filename + .xls);
OutputStream out = webResponse.getOutputStream();
myWorkBook.write(out);
out.close();
}

The sheet is still being populated as I need, and the client is asked to
open or save the filename.xls file (as expected).

The problem with 1.6 is: the current page is sent rather than the sheet I've
built.   My .xls viewer complains that the file is not in the correct format
and, when I display it anyway, contains the original Wicket page, head, css,
javascript and all.

The same problems happens when generating xml from the same data list:

WebResponse response = (WebResponse)getResponse();
response.setContentType(application/xml);
response.setAttachmentHeader(filename + .xml);
XMLStreamWriter out =
XMLOutputFactory.newInstance().createXMLStreamWriter(response.getOutputStrea
m());

out.writeStartDocument();
... (generate XML document from dataList)
out.writeEndDocument();
out.close();

This also sends the original HTML page to the client. 

Both methods worked perfectly before I migrated to Wicket 1.6, but now the
Response (returned by getResponse()) seems to behave differently.  Any
ideas?  Thank you very much.



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to
-Client-fails-in-1-6-tp4660579.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Generating spreadsheet to send to Client fails in 1.6

2013-07-31 Thread BrianWilliams
Thank you Paul.  I appreciate the advice.  Regarding your suggestion to use 
IResourceStream, I wonder what the problem is with writing to the web response? 
 Is this simply something that is no longer supported in 6.x, even though it 
worked perfectly in 4.x?  

I'd prefer to simply fix whatever is wrong with my current code
 


 From: Paul Bors [via Apache Wicket] ml-node+s1842946n4660582...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Wednesday, July 31, 2013 11:40 AM
Subject: RE: Generating spreadsheet to send to Client fails in 1.6
  


I think you should also upgrade your Apache POI version and switch to .xlsx 
since the older format has a limit of about 65K records. Outside of that I 
suggest you use an IResourceStream instead of writing to your web response. 

Personally I use csv comma delimited since I don't do any magic beside 
export those records to be viewed in Excel, edited and then imported back 
via the webapp. 

In any event this is how I do it via Wicket 6.x: 

@Override 
protected void onClick() { 
    IResourceStream csvStream = new 
CsvResourceStream(service.exportAll(getSession().getLocale())); 
    String fileNameKey = ...; 
    getRequestCycle().scheduleRequestHandlerAfterCurrent( 
        new 
ResourceStreamRequestHandler(csvStream).setFileName(ResourceKeyHelper.resour 
ceValue(fileNameKey) + .csv) 
    ); 
} 

public class CsvResourceStream extends AbstractResourceStream { 
    private static final long serialVersionUID = 1L; 
    
    public CsvResourceStream(ByteArrayOutputStream outputStream) { 
        super(outputStream.toByteArray()); 
        IOUtils.closeQuietly(outputStream); 
    } 
    
    @Override 
    public String getContentType() { 
        return new StringBuilder() 
            .append(text/comma-separated-values, ) 
            .append(text/csv, ) 
            .append(application/csv, ) 
            .append(application/excel) 
            .toString(); 
    } 
} 

You can switch it to your HSSFWorkbook and grab its byte content. 

-Original Message- 
From: BrianWilliams [mailto:[hidden email]] 
Sent: Wednesday, July 31, 2013 1:14 PM 
To: [hidden email] 
Subject: Generating spreadsheet to send to Client fails in 1.6 

Hello, 

I had code in Wicket 1.x that worked perfectly to dynamically generate a 
spreadsheet and send it to the user.  I had to rewrite it for the new 
Response classes in 1.6: 

    public void generateExcel(String filename, ListListlt;? extends 
Object dataList) { 
        HSSFWorkbook myWorkBook = new HSSFWorkbook(); 
        HSSFSheet mySheet = myWorkBook.createSheet(); 
        ... (generate sheet from dataList using HSSFSheet methods) 
        WebResponse response = (WebResponse)getResponse(); 
        webResponse.setContentType(application/vnd.ms-excel); 
        webResponse.setAttachmentHeader(filename + .xls); 
        OutputStream out = webResponse.getOutputStream(); 
        myWorkBook.write(out); 
        out.close(); 
    } 

The sheet is still being populated as I need, and the client is asked to 
open or save the filename.xls file (as expected). 

The problem with 1.6 is: the current page is sent rather than the sheet I've 
built.   My .xls viewer complains that the file is not in the correct format 
and, when I display it anyway, contains the original Wicket page, head, css, 
javascript and all. 

The same problems happens when generating xml from the same data list: 

    WebResponse response = (WebResponse)getResponse(); 
    response.setContentType(application/xml); 
    response.setAttachmentHeader(filename + .xml); 
    XMLStreamWriter out = 
XMLOutputFactory.newInstance().createXMLStreamWriter(response.getOutputStrea 
m()); 

    out.writeStartDocument(); 
    ... (generate XML document from dataList) 
    out.writeEndDocument(); 
    out.close(); 

This also sends the original HTML page to the client. 

Both methods worked perfectly before I migrated to Wicket 1.6, but now the 
Response (returned by getResponse()) seems to behave differently.  Any 
ideas?  Thank you very much. 



-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to
-Client-fails-in-1-6-tp4660579.html 
Sent from the Users forum mailing list archive at Nabble.com. 

- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 



- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 


~ Thank you, 
    p...@bors.ws  




 
If you reply to this email, your message will be added to the discussion below: 
http://apache-wicket.1842946.n4.nabble.com/Generating-spreadsheet-to-send-to-Client-fails-in-1-6-tp4660579p4660582.html
  
To unsubscribe from Generating spreadsheet to send to Client fails in 1.6, 
click 

RE: Generating spreadsheet to send to Client fails in 1.6

2013-07-31 Thread Paul Bors
Well... Component.getResponse() calls getRequestCycle().getResponse() and 
you're then you're casting that Response object to a WebResponse and change it 
in the middle of wicket's processing it.

Is simple to schedule your resource outside of wicket's normal flow right? 
Hence getRequestCycle().scheduleRequestHandlerAfterCurrent() which schedules 
the request handler to be executed after the current one works much better for 
downloading a resource right?

If you don't like that explanation look over the JavaDoc of the WebResponse and 
its API and compare it with that of the IResourceStream.

You have to ask yourself, are you going to set any cookies or a buffer along 
with your spreadsheet download? :)

~ Thank you,
  Paul Bors


-Original Message-
From: BrianWilliams [mailto:brianwilliams33...@yahoo.com] 
Sent: Wednesday, July 31, 2013 4:43 PM
To: users@wicket.apache.org
Subject: Re: Generating spreadsheet to send to Client fails in 1.6

Thank you Paul.  I appreciate the advice.  Regarding your suggestion to use 
IResourceStream, I wonder what the problem is with writing to the web response? 
 Is this simply something that is no longer supported in 6.x, even though it 
worked perfectly in 4.x?  

I'd prefer to simply fix whatever is wrong with my current code
 


 From: Paul Bors [via Apache Wicket] ml-node+s1842946n4660582...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Wednesday, July 31, 2013 11:40 AM
Subject: RE: Generating spreadsheet to send to Client fails in 1.6
  


I think you should also upgrade your Apache POI version and switch to .xlsx 
since the older format has a limit of about 65K records. Outside of that I 
suggest you use an IResourceStream instead of writing to your web response. 

Personally I use csv comma delimited since I don't do any magic beside 
export those records to be viewed in Excel, edited and then imported back 
via the webapp. 

In any event this is how I do it via Wicket 6.x: 

@Override 
protected void onClick() { 
IResourceStream csvStream = new 
CsvResourceStream(service.exportAll(getSession().getLocale())); 
String fileNameKey = ...; 
getRequestCycle().scheduleRequestHandlerAfterCurrent( 
new 
ResourceStreamRequestHandler(csvStream).setFileName(ResourceKeyHelper.resour 
ceValue(fileNameKey) + .csv) 
); 
} 

public class CsvResourceStream extends AbstractResourceStream { 
private static final long serialVersionUID = 1L; 

public CsvResourceStream(ByteArrayOutputStream outputStream) { 
super(outputStream.toByteArray()); 
IOUtils.closeQuietly(outputStream); 
} 

@Override 
public String getContentType() { 
return new StringBuilder() 
.append(text/comma-separated-values, ) 
.append(text/csv, ) 
.append(application/csv, ) 
.append(application/excel) 
.toString(); 
} 
} 

You can switch it to your HSSFWorkbook and grab its byte content. 

-Original Message- 
From: BrianWilliams [mailto:[hidden email]] 
Sent: Wednesday, July 31, 2013 1:14 PM 
To: [hidden email] 
Subject: Generating spreadsheet to send to Client fails in 1.6 

Hello, 

I had code in Wicket 1.x that worked perfectly to dynamically generate a 
spreadsheet and send it to the user.  I had to rewrite it for the new 
Response classes in 1.6: 

public void generateExcel(String filename, ListListlt;? extends 
Object dataList) { 
HSSFWorkbook myWorkBook = new HSSFWorkbook(); 
HSSFSheet mySheet = myWorkBook.createSheet(); 
... (generate sheet from dataList using HSSFSheet methods) 
WebResponse response = (WebResponse)getResponse(); 
webResponse.setContentType(application/vnd.ms-excel); 
webResponse.setAttachmentHeader(filename + .xls); 
OutputStream out = webResponse.getOutputStream(); 
myWorkBook.write(out); 
out.close(); 
} 

The sheet is still being populated as I need, and the client is asked to 
open or save the filename.xls file (as expected). 

The problem with 1.6 is: the current page is sent rather than the sheet I've 
built.   My .xls viewer complains that the file is not in the correct format 
and, when I display it anyway, contains the original Wicket page, head, css, 
javascript and all. 

The same problems happens when generating xml from the same data list: 

WebResponse response = (WebResponse)getResponse(); 
response.setContentType(application/xml); 
response.setAttachmentHeader(filename + .xml); 
XMLStreamWriter out = 
XMLOutputFactory.newInstance().createXMLStreamWriter(response.getOutputStrea 
m()); 

out.writeStartDocument(); 
... (generate XML document from dataList) 
out.writeEndDocument(); 
out.close(); 

This also sends the original HTML page to the client. 

Both methods worked perfectly before I migrated to Wicket 1.6, but now the 
Response (returned by getResponse()) 

Re: Generating spreadsheet to send to Client fails in 1.6

2013-07-31 Thread BrianWilliams
Thank you again Paul.  I'll look at scheduleRequestHandlerAfterCurrent and 
compare it.
 
And yes, you are right that IResourceStream is straightforward, but again I am 
blown away that something that worked perfectly pre6.x now requires a different 
strategy.  And no, I am not setting cookies or buffering, just generating and 
sending that spreadsheet down.
Cheers.
  


 From: Paul Bors [via Apache Wicket] ml-node+s1842946n4660599...@n4.nabble.com
To: BrianWilliams brianwilliams33...@yahoo.com 
Sent: Wednesday, July 31, 2013 4:24 PM
Subject: RE: Generating spreadsheet to send to Client fails in 1.6
  


Well... Component.getResponse() calls getRequestCycle().getResponse() and 
you're then you're casting that Response object to a WebResponse and change it 
in the middle of wicket's processing it. 

Is simple to schedule your resource outside of wicket's normal flow right? 
Hence getRequestCycle().scheduleRequestHandlerAfterCurrent() which schedules 
the request handler to be executed after the current one works much better for 
downloading a resource right? 

If you don't like that explanation look over the JavaDoc of the WebResponse and 
its API and compare it with that of the IResourceStream. 

You have to ask yourself, are you going to set any cookies or a buffer along 
with your spreadsheet download? :) 

~ Thank you, 
  Paul Bors 


-Original Message- 
From: BrianWilliams [mailto:[hidden email]] 
Sent: Wednesday, July 31, 2013 4:43 PM 
To: [hidden email] 
Subject: Re: Generating spreadsheet to send to Client fails in 1.6 

Thank you Paul.  I appreciate the advice.  Regarding your suggestion to use 
IResourceStream, I wonder what the problem is with writing to the web response? 
 Is this simply something that is no longer supported in 6.x, even though it 
worked perfectly in 4.x?   

I'd prefer to simply fix whatever is wrong with my current code 
  

 
 From: Paul Bors [via Apache Wicket] [hidden email] 
To: BrianWilliams [hidden email] 
Sent: Wednesday, July 31, 2013 11:40 AM 
Subject: RE: Generating spreadsheet to send to Client fails in 1.6 
  


I think you should also upgrade your Apache POI version and switch to .xlsx 
since the older format has a limit of about 65K records. Outside of that I 
suggest you use an IResourceStream instead of writing to your web response. 

Personally I use csv comma delimited since I don't do any magic beside 
export those records to be viewed in Excel, edited and then imported back 
via the webapp. 

In any event this is how I do it via Wicket 6.x: 

@Override 
protected void onClick() { 
    IResourceStream csvStream = new 
CsvResourceStream(service.exportAll(getSession().getLocale())); 
    String fileNameKey = ...; 
    getRequestCycle().scheduleRequestHandlerAfterCurrent( 
        new 
ResourceStreamRequestHandler(csvStream).setFileName(ResourceKeyHelper.resour 
ceValue(fileNameKey) + .csv) 
    ); 
} 

public class CsvResourceStream extends AbstractResourceStream { 
    private static final long serialVersionUID = 1L; 
    
    public CsvResourceStream(ByteArrayOutputStream outputStream) { 
        super(outputStream.toByteArray()); 
        IOUtils.closeQuietly(outputStream); 
    } 
    
    @Override 
    public String getContentType() { 
        return new StringBuilder() 
            .append(text/comma-separated-values, ) 
            .append(text/csv, ) 
            .append(application/csv, ) 
            .append(application/excel) 
            .toString(); 
    } 
} 

You can switch it to your HSSFWorkbook and grab its byte content. 

-Original Message- 
From: BrianWilliams [mailto:[hidden email]] 
Sent: Wednesday, July 31, 2013 1:14 PM 
To: [hidden email] 
Subject: Generating spreadsheet to send to Client fails in 1.6 

Hello, 

I had code in Wicket 1.x that worked perfectly to dynamically generate a 
spreadsheet and send it to the user.  I had to rewrite it for the new 
Response classes in 1.6: 

    public void generateExcel(String filename, ListListlt;? extends 
Object dataList) { 
        HSSFWorkbook myWorkBook = new HSSFWorkbook(); 
        HSSFSheet mySheet = myWorkBook.createSheet(); 
        ... (generate sheet from dataList using HSSFSheet methods) 
        WebResponse response = (WebResponse)getResponse(); 
        webResponse.setContentType(application/vnd.ms-excel); 
        webResponse.setAttachmentHeader(filename + .xls); 
        OutputStream out = webResponse.getOutputStream(); 
        myWorkBook.write(out); 
        out.close(); 
    } 

The sheet is still being populated as I need, and the client is asked to 
open or save the filename.xls file (as expected). 

The problem with 1.6 is: the current page is sent rather than the sheet I've 
built.   My .xls viewer complains that the file is not in the correct format 
and, when I display it anyway, contains the original Wicket page, head, css, 
javascript and all. 

The same problems happens when generating