users@jersey.java.net

Re: [Jersey] Jersey explicit MVC

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 28 Apr 2009 18:03:09 +0200

On Apr 28, 2009, at 5:37 PM, Nabil Benothman wrote:

>
> Hi,
> thanks for your answer but where the « JSPTemplateProcessor » is
> called,

The answer is a little involved... there is a message body writer that
is responsible for processing instances of Viewable, that defers to
the registered template processors to resolve an absolute template
name into a fully qualified template name.

If say you have a resource class FooResource:

package foo;

public class FooResource {
   @GET
   public Viewable get() {
     return new Viewable("index.jsf, "MODEL");
   }
}


then because the template name "index.jsf" is not absolute it will be
resolved to an absolute template name given the FooResource:

   index.jsf -> /foo/FooResource/index.jsf

Then the template processors will be check to see if they can resolve
the absolute template name to a fully qualified template name.

Specifically for the JSPTemplateProcessor it will be resolved if:

   servletContext.getResource("/foo/FooResource/index.jsf")

returns a non-null value. Namely, there exists a file "/foo/
FooResource/index.jsf" in the web pages area.

If that file exists then Jersey will forward the servlet request to
that resource.


> do
> I need some additional configuration like adding some settings in the
> web.xml, etc..?

No, for explicit returning of Viewable instances as you are doing, the
JSP viewable support will be enabled because you are using the Jersey
servlet.


> and I think that the class « HttpResponseAdaptor » does not
> exist in the jsr311-api implementation.
>

Hmm... what version of Jersey are you using?

Can you send me the directory layout of your project, specifically the
files in the Web pages area?

Paul.

>
> jstrachan wrote:
>>
>> 2009/4/28 Nabil Benothman <nabil.benothman_at_gmail.com>:
>>>
>>> Hello everyone,
>>> I am starting with the framework jersey and I have a little
>>> problem with
>>> the
>>> explicit MVC. To use facelets (. xhtml), I had to go through a jsp
>>> in
>>> which
>>> I forward to the JSF. So my question is: « is there another
>>> alternative
>>> to
>>> do so without having to go through the jsp » ie instead of
>>> returning «
>>> new
>>> Viewable (" index.jsp ", entity);» we return directly «new
>>> Viewable ("
>>> index.jsf ", entity)».
>>> the code is as follows :
>>>
>>> // resource
>>> ....
>>> @GET
>>> @Produces(MediaType.TEXT_HTML)
>>> public Viewable get() {
>>> EntityManager em =
>>> PersistenceService.getInstance().getEntityManager();
>>>
>>> Collection<UbikeUser> users = (Collection<UbikeUser>)
>>> em.createNamedQuery(
>>> "user.getAll").getResultList();
>>>
>>> return new Viewable("/usersInfo.jsp", users);
>>
>> You could probably write a JSFTemplateProcessor (see the source of
>> JSPTemplateProcessor in jersey-server) and then change the above code
>> to
>>
>> return new Viewable("/usersInfo.jsf", users);
>>
>> I've not used JSF so not sure if there's any gotchas though; but I'd
>> have thought it should work?
>>
>> --
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://fusesource.com/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/Jersey-explicit-MVC-tp2732209p2734229.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>