Re: Application-aware JSPs?
"Daniel P. Berrange" <[email protected]> Mon, 10 May 2004 19:11:27 +0100
| Newsgroups | gmane.linux.redhat.ccm.general |
|---|---|
| Message-ID | <[email protected]> |
On Mon, May 10, 2004 at 01:38:23PM -0400, Jeff K. Hoffman wrote:
> Hello, list.
>
> Over the weekend, I did some more experimentation with CCM 6.1 and JSPs.
> After following Daniel Berrange's advice, I converted my application to
> use ApplicationFileServlet, with my JSPs in web/templates/myapp.
>
> Surprisingly, I was not able to access the current application instance
> inside a JSP. Or, if I could, I couldn't figure out how to get a
> reference to it. My test JSP was something like this:
>
> <%@page extends="com.arsdigita.web.BaseJSP"
> import="com.arsdigita.web.Web" %>
>
> <html>
> <body>
> <%= Web.getContext().getApplication() %>
> </body>
> </html>
>
> It displays 'null'.
>
> After looking through the code, I noticed that the application is not
> set in the context by BaseServlet (the ancestor of BaseJSP), but by
> BaseApplicationServlet. In the absence of a BaseApplicationJSP, I
> decided to make my own, only to be shut down by the fact that the
> doService(req, resp) method of BaseApplicationServlet is declared
> 'final', and cannot be overridden.
>
> Of course, all of this is a mental excercise; I have no real-world need
> to access the Application instance in my JSP. Yet. I just assumed it
> would be a normal thing to do.
It somewhat depends on how (what URL) you request the JSP. If
for example you request it via the mounted application, eg
/ccm/myapp/index.xml
Then this initial request will be served by DispatcherServlet.
This delegates most of its logic to BaseDispatcher, which is
what does the resolution of /ccm/myapp into an instance of
the com.example.MyApp class. Having resolved an application,
it sets up the WebContext & forwards onto the servlet defined
by 'getServletPath' method of MyApp. ie the ApplicationFileServlet.
Now, the ApplicationFileServlet forwards onto a concrete JSP
file on disk, eg /templates/ccm-myapp/index.jsp
So, the bottom line is that if the requests for your JSP file
come in via /ccm/myapp/... the WebContext will be populated with
the correct Application instance before your JSP is invoked.
The only situation in which Web.getContext().getApplication() can
return null, is if you are requesting the JSP directly with its
concrete URL,
ie, /templates/ccm-myapp/index.jsp
instead of the correct
/ccm/myapp/index.xml
The BaseJSP class is intended for JSPs which want to bypass
the DispatcherServlet/BaseDispatcher stuff altogether. As
such it only sets up the current Party & Locale, but none of
the Application context. If your JSPs are going via the
BaseDispatcher there is no need to have 'extends=BaseJSP'
tag since this stuff will have already been setup for you.
Creating a BaseApplicationJSP for situations where you want
to use the Application objects framework, but not BaseDispatcher
smacks of wheel re-invention to me. Since your BaseApplicationJSP
would basically end up duplicating all of what BaseDispatcher does
you might as well take advantage of the existing BaseDispatcher
stuff in the first place.
Da.
--
|=- Daniel P. Berrange - [email protected] -=|
|=- Red Hat, 338 Euston Road, London, NW1 3BT. +44 (0)7977 267 243 -=|
|=- -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
--
Redhat-ccm-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/redhat-ccm-list
Archives: https://www.redhat.com/pipermail/redhat-ccm-list/
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFAn8XOs9/3Qn07lQURAru7AKCLxfOCV2bY+twEs+llaUzIILwxqQCfWaki GVBnbLgtwyF/FHU7M/HxpPo= =ZMlw -----END PGP SIGNATURE-----