wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl-Eric Menzel <cmen...@wicketbuch.de>
Subject Re: Migration issue: page that writes binary data to the response
Date Mon, 18 Feb 2013 20:16:01 GMT
On Mon, 18 Feb 2013 19:03:41 +0100
Martin Dietze <di@fh-wedel.de> wrote:

> On Mon, February 18, 2013, Carl-Eric Menzel wrote:
> 
> > Is there a particular reason you're using a page?
> 
> One - unfortunately - big reason: it's legacy code (most of
> which I did not even write myself). The Wicket upgrade is badly
> needed for browser compatibiy, however I don't want to change
> code if it's not absolutely necessary. 

For generating binaries, I would *really* recommend doing this change.
Pages simply are not a good fit for that. Also, it shouldn't be that
big of a change, since you're writing to the Response anyway. Within
AbstractResource's WriteCallback you're going to use the same Response
object, so you can simply copy most of your code over without much
change.

(pseudocode from memory, but close enough)

MyResource extends AbstractResource {
 @Override newResourceResponse(Attributes att) {
  att.setFilename("foo.pdf");
  att.disableCaching();
  att.setContentType("text/pdf");
  att.setWriteCallback(new WriteCallback() {
    @Override writeData(Attributes att) {
      Response r = att.getResponse();
      // write to the response here like you did before
    }
  });
 }
}

Except in this case you won't have to mangle the Response object like
you have to do with the page.

Carl-Eric


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


Mime
View raw message