users@jersey.java.net

Re: [Jersey] Using JSP for HTML representation

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 28 Aug 2008 11:52:00 +0200

Hi,

There are some things i left out of the blog entry so as not to
complicate things.

When resolving a template reference to an absolute template reference
Jersey will also traverse the class hierarchy of the resource class.

So, for example, if class com.foo.Foo extends com.bar.Bar, then if no
template is found for Foo then a search will be performed for Bar.

In addition, for JSPs, there is a tag lib extension for inclusion that
searches using the class hierarchy. This is used in the Bookstore
example. The class Book extends the class Item. The index.jsp for Book
contains the following:

         <rbt:include page="footer.jsp"/>

There is no footer.jsp present for Book, but a footer.jsp is present for
Item.

Paul.

[1]
http://download.java.net/maven/2/com/sun/jersey/samples/bookstore/0.11-ea-SNAPSHOT/bookstore-0.11-ea-SNAPSHOT-project.zip

Tyson Norris wrote:
> You can use "explicit" jsp pages also, which makes things a bit more clear, I think.
>
> The short answer is: in your resource method, return com.sun.jersey.api.view.Viewable instead of your JAXB type.
>
> The Viewable instance in constructed with:
> - your data object (maybe a JAXB type, maybe some arbitrary type), that can be referenced via ${it} context var within the jsp page
> - path to your jsp page
>
> See Paul's blog entry regarding this here:
> http://blogs.sun.com/sandoz/entry/mvcj
>
> Tyson
>
>
>
> -----Original Message-----
> From: Kevin Duffey [mailto:andjarnic_at_yahoo.com]
> Sent: Fri 8/22/2008 10:12 PM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Using JSP for HTML representation
>
> Hey,
>
> I am guessing here.. but looking at the web.xml for that example:
>
> <init-param>
> <param-name>com.sun.jersey.config.feature.Redirect</param-name>
> <param-value>true</param-value>
> </init-param>
> <init-param>
> <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
> <param-value>true</param-value>
> </init-param>
>
>
> Not sure if that helps it, but my guess is the response is somehow "redirected" back to the jsp page... based on the Redirect param and ImplicitViewables param above. I really don't see tho looking at it how each jsp page gets called, but another guess is the name of the jsp page is in the same path as that of the Resource... that is com\sun\jersey\samples\bookstore\resources seems to be the package names for the java classes, and the same "path" for the jsp pages.
>
> Maybe you can mess around with that and see what happens.
>
>
>
>
> ----- Original Message ----
> From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
> To: users_at_jersey.dev.java.net
> Sent: Friday, August 22, 2008 6:25:44 PM
> Subject: [Jersey] Using JSP for HTML representation
>
>
> Hi,
>
> The bookstore example shows how to use JSP pages for resources. How does jersey decide to use this page when returning the response? I'm returning an instance of a @XmlRootElement annotated class, and there's a provider in the jersey library that has a "*/*" producer, so I'm getting an XML document in response when doing a GET with Accept: text/html.
>
> Is there a way to have my application return the JSP generated page instead?
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109