Re: [Wicket-user] Re: Servlet forward to a JSP

2005-11-16 Thread Alexandru Popescu
I think a very nice addition to this would be to allow the included JSP to have access to the 
current component model.


./alex
--
.w( the_mindstorm )p.

#: Robert McClay changed the world a bit at a time by saying on  11/14/2005 
9:27 AM :#
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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user





---
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628alloc_id=16845op=click
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Re: Servlet forward to a JSP

2005-11-14 Thread Juergen Donnerstag
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
 Wicket-user@lists.sourceforge.net
 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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


[Wicket-user] Re: Servlet forward to a JSP

2005-11-06 Thread Robert McClay
If I come up with anything useful I'd be happy to contribute. The JSP I 
need to forward to requires request attributes, so I don't think the 
wicket.markup.html.include.Include component will work as from what I 
understand it is a separate request whose output is then included into 
the markup? In this case, the result of RedirectPage would be the same 
as it is a fresh browser request and I need to populate a request with 
request.setAttribute() and have the JSP be able to retrieve the request 
attributes. What I'm looking for is a way in Wicket to tell it to 
finish its processing, not output any markup, and then forward the 
request to another servlet, not include or redirect.  Thanks.


On 2005-11-06 15:38:06 -0700, Eelco Hillenius [EMAIL PROTECTED] said:


Sure. Use wicket.markup.html.pages.RedirectPage for server-side
redirecting to a non-wicket locations. If you want to inlcude things
likes JSP pages into Wicket pages, you can use the
wicket.markup.html.include.Include component. The latter is a bit
rough, so if you need better support on that one, please contribute ;)

Eelco


On 11/6/05, Robert McClay [EMAIL PROTECTED] wrote:

I'm exploring the possibility of integrating Wicket into a JSP
application. Is it possible to tell Wicket to do a servlet forward to a
JSP? I would like to add a few request attributes and then forward to a
JSP. The reason I'd like to do a forward VS include is I need to be
able to populate request attributes prior to the JSP running. The login
page is currently implemented in JSP. Another option would be to
refactor the login page, but I'm curious if it is feasibile to attempt
the former as I want to use as much of the existing system as possible.
Thanks.




---
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Downl oad
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
Wicket-user@lists.sourceforge.net
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






---
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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] Re: Servlet forward to a JSP

2005-11-06 Thread Eelco Hillenius
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

Eelco


On 11/6/05, Robert McClay [EMAIL PROTECTED] wrote:
 If I come up with anything useful I'd be happy to contribute. The JSP I
 need to forward to requires request attributes, so I don't think the
 wicket.markup.html.include.Include component will work as from what I
 understand it is a separate request whose output is then included into
 the markup? In this case, the result of RedirectPage would be the same
 as it is a fresh browser request and I need to populate a request with
 request.setAttribute() and have the JSP be able to retrieve the request
 attributes. What I'm looking for is a way in Wicket to tell it to
 finish its processing, not output any markup, and then forward the
 request to another servlet, not include or redirect.  Thanks.

 On 2005-11-06 15:38:06 -0700, Eelco Hillenius [EMAIL PROTECTED] said:

  Sure. Use wicket.markup.html.pages.RedirectPage for server-side
  redirecting to a non-wicket locations. If you want to inlcude things
  likes JSP pages into Wicket pages, you can use the
  wicket.markup.html.include.Include component. The latter is a bit
  rough, so if you need better support on that one, please contribute ;)
 
  Eelco
 
 
  On 11/6/05, Robert McClay [EMAIL PROTECTED] wrote:
  I'm exploring the possibility of integrating Wicket into a JSP
  application. Is it possible to tell Wicket to do a servlet forward to a
  JSP? I would like to add a few request attributes and then forward to a
  JSP. The reason I'd like to do a forward VS include is I need to be
  able to populate request attributes prior to the JSP running. The login
  page is currently implemented in JSP. Another option would be to
  refactor the login page, but I'm curious if it is feasibile to attempt
  the former as I want to use as much of the existing system as possible.
  Thanks.
 
 
 
 
  ---
  SF.Net email is sponsored by:
  Tame your development challenges with Apache's Geronimo App Server. Downl 
  oad
  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
  Wicket-user@lists.sourceforge.net
  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





 ---
 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
 Wicket-user@lists.sourceforge.net
 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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user