Hi, Extend MountedMapper and override its mapRequest() method. When a request comes render the page and send it as email. After that return TextRequestHandler("OK") to indicate the success or ErrorCodeRequestHandler for the failure.
On Tue, Nov 15, 2011 at 12:31 PM, Dirk Forchel <dirk.forc...@exedio.com> wrote: > Okay, this is the preferred way if I would have a link on the page, but I > have not. This is also the way like the DownloadLink works: > > @Override > public void onClick() > { > ... > getRequestCycle().scheduleRequestHandlerAfterCurrent( > new ResourceStreamRequestHandler(resourceStream) > { > @Override > public void respond(IRequestCycle requestCycle) > { > super.respond(requestCycle); > if (deleteAfter) > { > Files.remove(file); > } > } > > }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); > } > > But I don't have any Link on the page. Instead the page is used as > "template" and the "onCapture" method of the > CapturingBookmarkablePageRequestTarget was used to sent the email (like the > staticpage example from Wicket 1.4). I thought I should implement an > *IRequestMapper* and an *IRequestHandler* in Wicket 1.5 to achieve the same > and to replace the CodingStrategy and the RequestTarget which are obsolete > in Wicket 1.5. > Would be nice to get this simple example work in Wicket 1.5 too. > > EmailPage.java: > > public class EmailPage extends WebPage > { > public EmailPage() > { > // > } > } > > EmailPage.html: > > <html> > <head> > <title>Email Page</title> > </head> > <body> > <p>This is the captured page sent by email.</p> > </body> > </html> > > Sent.java: > > public class Sent extends WebPage > { > > } > > Sent.html: > > <html> > <head> > <title>Sent Page</title> > </head> > <body> > <p>*The email has been sent!*</p> > <p>Well, that's if you have a little bit of imagination. But > for now the > page has been dumped to stdout. Sending > the real email is left as an exercise for the reader.</p> > </body> > </html> > > CapturingBookmarkablePageRequestTarget.java: > > public abstract class CapturingBookmarkablePageRequestTarget extends > BookmarkablePageRequestTarget > { > Class<? extends Page> displayedPageClass; > > public <C extends Page, D extends Page> > CapturingBookmarkablePageRequestTarget( > Class<C> capturedPageClass, Class<D> displayedPageClass, > PageParameters > pageParameters) > { > super(capturedPageClass, pageParameters); > this.displayedPageClass = displayedPageClass; > } > > @Override > public void respond(RequestCycle requestCycle) > { > final StringResponse emailResponse = new StringResponse(); > final WebResponse originalResponse = > (WebResponse)RequestCycle.get().getResponse(); > RequestCycle.get().setResponse(emailResponse); > super.respond(requestCycle); > onCapture(emailResponse); > RequestCycle.get().setResponse(originalResponse); > RequestCycle.get().setRequestTarget(new > BookmarkablePageRequestTarget(displayedPageClass)); > } > > protected abstract void onCapture(StringResponse emailResponse); > } > > CapturingBookmarkablePageRequestTargetUrlCodingStrategy.java: > > public class CapturingBookmarkablePageRequestTargetUrlCodingStrategy extends > BookmarkablePageRequestTargetUrlCodingStrategy > { > Class<? extends Page> capturedPageClass; > Class<? extends Page> displayedPageClass; > > public <C extends Page, D extends Page> > CapturingBookmarkablePageRequestTargetUrlCodingStrategy( > String mountPath, Class<C> capturedPageClass, Class<D> > displayedPageClass) > { > super(mountPath, capturedPageClass, null); > this.displayedPageClass = displayedPageClass; > this.capturedPageClass = capturedPageClass; > } > > @Override > public IRequestTarget decode(RequestParameters requestParameters) > { > return new > CapturingBookmarkablePageRequestTarget(capturedPageClass, > displayedPageClass) > { > @Override > protected void onCapture(StringResponse emailResponse) > { > // Here send the email instead of dumping it > to stdout! > System.out.println(emailResponse.toString()); > } > }; > } > } > > Application#init(): > > // All requests to bookmarkable page "Page" will be captured, and the > // "Sent" page is shown instead > mount(new > CapturingBookmarkablePageRequestTargetUrlCodingStrategy("/capturedpage", > EmailPage.class, Sent.class)); > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Capture-the-response-of-a-page-request-and-displays-another-page-as-result-tp4039468p4042468.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 > > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com