On Mon, Apr 6, 2009 at 12:18 PM, Peter Ross wrote:
> Hi,
>
> I'm new to wicket and I am looking at integrating Prince XML with Wicket.
>
> Prince supplies a method
>
> public boolean convert(InputStream xmlInput, OutputStream pdfOutput)
> throws IOException
>
> What I would like to do is add this into the rendering pipeline for a
> page, so that I can get the HTML of the page as a stream and then
> return the page as a PDF.
>
> I've explored the mailing list and examples and the closest example I
> can find is for sending an email at
>
> http://www.wicket-library.com/wicket-examples/staticpages/
>
> and I was wondering is this the correct approach, or should I be
> looking at something else?
>
I ended up pretty much following the code from the static pages
example, except I use requestCycle.setRedirect(false) rather than
using mount and having a special
BookmarkablePageRequestTargetUrlCodingStrategy.
As far as I can tell the only problem with doing it my way is the
"double submit" problem. However as long as the page I render doesn't
do any state updates then this is not a problem because all that will
happen is that I will get the file being generated twice on the
server.
Here is the code that I'm using:
public class PdfPageRequestTarget extends BookmarkablePageRequestTarget {
private String filename;
public PdfPageRequestTarget(java.lang.Class PageClass, String filename) {
super(PageClass);
this.filename = filename;
}
@Override
public void respond(RequestCycle requestCycle) {
// In the staticpages example of wicket there is the
following comment:
// Unfortunately, you cannot use
// CapturingBookmarkablePageRequestTarget in an event listener
// like onClick() unless you change the application's
// IRequestCycleSettings to ONE_PASS_RENDER
//
// Thus we setRedirect to be false, meaning that ONE_PASS_RENDER is
// enabled for just this request. If you don't then s.ToString()
// returns the empty string.
requestCycle.setRedirect(false);
// Save the web response we are rendering into
WebResponse w = (WebResponse) requestCycle.get().getResponse();
// Render into a string
StringResponse s = new StringResponse();
requestCycle.get().setResponse(s);
super.respond(requestCycle);
// Restore the web response
RequestCycle.get().setResponse(w);
// Now set up a text file which contains the requested pages html.
ResourceStreamRequestTarget target = new
ResourceStreamRequestTarget(new StringResourceStream(s.toString(),
"text/plain"));
target.setFileName(this.filename);
// Now request that the result of rendering be the text file.
requestCycle.get().setRequestTarget(target);
}
}
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org