users@jersey.java.net

Re: [Jersey] Questions on implicit views

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 09 Jul 2009 11:56:27 +0200

On Jul 6, 2009, at 11:56 PM, Louis Polycarpou wrote:

> I am working with Jersey's implicit views and would appreciate your
> help on the following issues:
>
> 1) I have a single resource which uses an index.jsp to render a
> (customer) list to the page. I am issuing a POST from a HTML form
> rendered by this index.jsp against the same resource which adds a
> new customer record. How do I then redirect the user back to the
> same page? Currently, I'm returning a Response object. What do I
> need to return in order to render the same index.jsp following a
> successful POST?
>
> @POST
> public Response addCust(@FormParam("name") String name,
> @FormParam("description") String desc) {
> try {
> int custId = persistCust(name, desc);
> return Response.ok().build(); // *** WHAT SHOULD I
> RETURN HERE TO RENDER THE IMPLICIT INDEX.JSP???
> } catch (Exception e) {
> throw new WebApplicationException(e,
> Response.Status.INTERNAL_SERVER_ERROR);
> }
> }
>

   return new Viewable("index.jsp", this);

The implicit views only work for GETs, namely stuff that will not
change the state of resources.


> 2) The resource in question is @Path /Customers. I'm hitting an
> intermittent problem where some of the ahref links are not correctly
> rendered by the JSP. I need all links to be relative to the current
> resource at e.g. http://webappname:8080/Customers/{id} but quite
> often the 'Customers' segment is left out.

Can you present more detail of when this occurs and when it does not?
when you say "intermittent" does it sometimes work and sometimes not
work?


> So obviously if I hardcode this into the implicit JSP view, it
> intermittently gets inserted twice. Is there a correct way to
> resolve links on the page so that they are relative to the implicit
> resource?
>
> 3) Finally, I would like to build something which renders a number
> of items on the page that are constructed from multiple REST calls.
> Sort of like a collection of REST portlets (sorry if that is a bad
> word!). Is there any support in Jersey for constructing a page from
> a series of REST calls?
>

Not specifically, for this i think you would require some form a
JavaScript library to make calls make to the Web application the
responses of which update the HTML DOM.

Paul.