Got it - found another hint about DownloadLink that led me to this solution:
@Override public void onSubmit() { ReportResource resource = new PdfReportResource(getReportName(), getParamsModel()); getRequestCycle().scheduleRequestHandlerAfterCurrent( new ResourceRequestHandler(resource, null)); } So simple, but it took some digging to find so hope this helps someone else. -- Jim. On Fri, Oct 21, 2011 at 2:44 PM, Jim Pinkham <pinkh...@gmail.com> wrote: > OK, I've almost got it - thanks for the example. > > It comes down to either using a ResourceLink<Void> which serves up the pdf > with no complaints, but despite being attached to a submit button, the form > doesn't seem to have been submitted; the parameters don't reflect any user > input > > or, I can solve that if I use a Button instead, and copy this code from > ResourceLink.onResourceRequested into the Button's onSubmit()... > > > Attributes a = new Attributes(RequestCycle.get().getRequest(), > RequestCycle.get() > .getResponse(), null); > resource.respond(a); > > But if I do that, it works but then I get "Header was already written to > response!" as mentioned earlier. > > I also tried making my own MyResourceLink (I would rather have extended > ResourceLink but I had to go all the way back to Link because ResourceLink's > onResourceRequested is final) and I put a call to > ParamsForm.this.process(this); then super.onResourceRequested(), and that > stopped the error but still didn't submit the form. > > Has anyone found a way to get the best of both? I found SubmitLink, but I > guess I need some way to 'mix that in', or decorate the ResourceLink with a > submit first... not sure how to do that.. (ResourceLink already implements > IFormSubmittingComponent, but I guess that's not enough) > > (I tried calling inputField.getConvertedInput() like I might do from a > validator but that just returns null, which is what leads me to believe the > form hasn't been submitted) > > Thanks, > -- Jim. > > > On Wed, Oct 19, 2011 at 11:55 PM, Martin Grigorov <mgrigo...@apache.org>wrote: > >> On Wed, Oct 19, 2011 at 11:46 PM, Paul Szulc <paul.sz...@gmail.com> >> wrote: >> > Ok, below the code I use to create a link that allows to download pdf >> file >> > created by jasper on runtime. Hope it helps. Do not hesitate to ask >> > questions. >> > >> > >> > public class PdfGenerateLink extends ResourceLink<Void> { >> > >> > public PdfGenerateLink(final String id, final IModel<Bid> model, >> final >> > PdfBuilderFromBidCreator creator) { >> > >> > super(id, new WebResource() { >> > @Override >> > public IResourceStream getResourceStream() { >> > IResourceStream resourceStream = new >> > AbstractResourceStreamWriter() { >> > >> > public void write(OutputStream output) { >> > try { >> > generate(output, model.getObject()); >> > } catch (Exception e) { >> > throw new RuntimeException(e); >> > } >> > } >> > >> > private void generate(OutputStream output, Bid bid) >> > throws Exception { >> > PdfOfertaDocumentBuilder pdf = >> creator.create(bid); >> Oferta ?! >> This sounds like Bulgarians are involved here :-) >> > InputStream generate = pdf.generate(); >> > byte[] buffer = new byte[1024]; >> > while (generate.read(buffer) != -1) { >> > output.write(buffer); >> > } >> > generate.close(); >> > } >> > >> > public String getContentType() { >> > return "application/pdf"; >> > } >> > }; >> > >> > return resourceStream; >> > } >> > >> > @Override >> > protected void setHeaders(WebResponse response) { >> > super.setHeaders(response); >> > response.setCharacterEncoding("UFT-8"); >> > response.setHeader("Expires", "0"); >> > response.setHeader("Cache-Control", "no-cache"); >> > response.setHeader("Cache-Control", "must-revalidate, >> > post-check=0, pre-check=0"); >> > response.setHeader("Pragma", "public"); >> > >> > >> response.setAttachmentHeader(model.getObject().getPublicTask().getName().replace(" >> > ", "_") + ".pdf"); >> > } >> > }); >> > add(createImage("icon", "pdficon16.png")); >> > } >> > } >> > >> > On Tue, Oct 18, 2011 at 8:43 PM, Jim Pinkham <pinkh...@gmail.com> >> wrote: >> > >> >> Paul, >> >> >> >> I am doing something very similar - I'd be interested to know more >> about >> >> how you got this working - here is what I've got that works for now, >> but I'm >> >> not real happy with it: >> >> >> >> In my report forms, I have buttons like this: (details about params >> >> omitted - nothing fancy there) >> >> >> >> add(new MyReportResourceButton("pdf", new >> >> ReportResource("MyReport", new PdfResourceHandler()), paramsModel)); >> >> add(new MyReportResourceButton("xls", new >> >> ReportResource("MyReport", new XlsResourceHandler()), paramsModel)); >> >> >> >> (So it will load MyReport.jasper that was compiled and put into >> resources >> >> folder by maven plugin during build) >> >> >> >> MyReportResourceButton has this: >> >> @Override >> >> public final void onResourceRequested() { >> >> Map<String,Object> params = paramsModel.getObject(); >> >> resource.setReportParameters(params); >> >> super.onResourceRequested(); >> >> } >> >> >> >> and it's superclass MyResourceButton has this: >> >> @Override >> >> public void onSubmit() { >> >> onResourceRequested(); >> >> } >> >> >> >> /** >> >> * @see org.apache.wicket.IResourceListener#onResourceRequested() >> >> */ >> >> public void onResourceRequested() >> >> { >> >> Attributes a = new Attributes(RequestCycle.get().getRequest(), >> >> RequestCycle.get() >> >> .getResponse(), null); >> >> resource.respond(a); >> >> } >> >> >> >> >> >> At runtime, it basically works, however, it gives me this annoying >> message >> >> in my logs multiple times per report request after the report has been >> >> served and it appears to be trying to just stay on the same page: >> >> >> >> 2011-10-13 15:22:42,381 [http-80-12] ERROR >> >> org.apache.wicket.DefaultExceptionMapper - Unexpected error occurred >> >> java.lang.IllegalStateException: Header was already written to >> response! >> >> at >> >> >> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.checkHeader(HeaderBufferingWebResponse.java:64) >> >> at >> >> >> org.apache.wicket.protocol.http.HeaderBufferingWebResponse.sendRedirect(HeaderBufferingWebResponse.java:112) >> >> at >> >> >> org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:136) >> >> at >> >> >> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:261) >> >> at >> >> >> org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:139) >> >> at >> >> >> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:717) >> >> at >> >> >> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:63) >> >> at >> >> >> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:96) >> >> at >> >> >> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) >> >> at >> >> >> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:253) >> >> at >> >> >> org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:160) >> >> at >> >> >> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:216) >> >> >> >> Could you tell me if there is some way this differs from how you (or >> your >> >> contractor) are doing it? >> >> >> >> Thanks, >> >> -- Jim. >> >> >> >> On Tue, Oct 18, 2011 at 3:58 AM, Paul Szulc <paul.sz...@gmail.com> >> wrote: >> >> >> >>> yeah, ok, my bad >> >>> >> >>> resources where under src/main/resource not src/main/resource*s* >> >>> * >> >>> * >> >>> thx Tor >> >>> >> >> >> >> >> > >> > >> > -- >> > Best regards, >> > Paul Szulc >> > >> > http://www.paulszulc.com >> > >> >> >> >> -- >> Martin Grigorov >> jWeekend >> Training, Consulting, Development >> http://jWeekend.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> >