Shouldn't we add such functionality to core? Or at least extension. I
understand that the way it is implemented is because he didn't want to
patch core, but I assume it can be put into core and made available to
users more easily: no specific request and response wrapper etc.
Juergen
On 11/14/05, Robert McClay <[EMAIL PROTECTED]> wrote:
> Here's a starting point if anyone wants to include a servlet / jsp in
> their page via RequestDispatcher.
>
> public class IncludeServlet extends WebComponent {
> private static final long serialVersionUID = 1L;
>
> public IncludeServlet(String id) {
> super(id);
> }
>
> public IncludeServlet(String id, IModel model) {
> super(id, model);
> }
>
> protected void onComponentTagBody(MarkupStream markupStream,
> ComponentTag openTag) {
> ServletWebRequest servletWebRequest =
> (ServletWebRequest) getRequest();
> HttpServletRequest request =
> servletWebRequest.getHttpServletRequest();
> WebResponse webResponse = (WebResponse)
> getRequestCycle().getOriginalResponse();
> HttpServletResponse response =
> webResponse.getHttpServletResponse();
> RequestDispatcher dispatcher = ((ServletWebRequest)
> getRequest()).getHttpServletRequest().getRequestDispatcher(getModelObjectAsString());
>
>
> GenericServletResponseWrapper wrappedResponse = new
> GenericServletResponseWrapper(response);
>
> try {
> dispatcher.include(request, wrappedResponse);
> } catch (ServletException e) {
> throw new RuntimeException(e);
> } catch (IOException e) {
> throw new RuntimeException(e);
> }
> replaceComponentTagBody(markupStream, openTag, new
> String(wrappedResponse.getData()));
> }
> }
>
> class GenericServletOutputStream extends ServletOutputStream {
> private OutputStream out;
>
> public GenericServletOutputStream(OutputStream out) {
> this.out = out;
> }
>
> public void write(int b) throws IOException {
> out.write(b);
> }
>
> public void write(byte[] b) throws IOException {
> out.write(b);
> }
>
> public void write(byte[] b, int off, int len) throws IOException {
> out.write(b, off, len);
> }
> }
>
> class GenericServletResponseWrapper extends HttpServletResponseWrapper {
> private ByteArrayOutputStream output;
>
> public GenericServletResponseWrapper(HttpServletResponse response) {
> super(response);
> output = new ByteArrayOutputStream();
> }
>
> public byte[] getData() {
> return output.toByteArray();
> }
>
> public ServletOutputStream getOutputStream() {
> return new GenericServletOutputStream(output);
> }
>
> public PrintWriter getWriter() {
> return new PrintWriter(getOutputStream(), true);
> }
> }
>
> On 2005-11-06 16:27:44 -0700, Eelco Hillenius <[EMAIL PROTECTED]> said:
>
> > Ah, yes. True. It used to resolve local includes using
> > javax.servlet.RequestDispatcher, i which case including request
> > attributes would work. However, that proved to be quite problametic
> > and we changed it to always use the absolute requests.
> >
> > What you need shouldn't be too hard however. But it is not something
> > Wicket supports out-of-the-box (and I'm not sure whether that would be
> > in Wicket's scope either).
> >
> > You don't need Wicket to tell stopping any processing, as that is
> > already part of the idea of component orientation. What you need (to
> > build) is a component that gets the content you want to include during
> > it's rendering process. E.g. by letting your component extend from
> > WebComponent and overriding method onComponentTagBody to do the work.
> > In this method, you'll probably want to use the request processor:
> >
> > RequestDispatcher dispatcher
> > ((ServletWebRequest)getRequest()).getHttpServletRequest()
> > .getRequestDispatcher("*path-to-jsp*");
> >
> > For the including.
> >
> > Eelco
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user