using Lift templates stand alone inside other frameworks like JAXRS?

47 views
Skip to first unread message

James Strachan

unread,
Apr 22, 2009, 7:47:44 AM4/22/09
to lif...@googlegroups.com
This might seem a truly bizarre request - particularly to folks who
solely use lift as their web framework; but I've been hacking up a
number of JAXRS services - I'm a big JAXRS fan (and slowly being drawn
to scala/lift).

I'd like to make Lift templates an option for any JAXRS developer
who's made a RESTful service and wants nice HTML/XML/Atom views using
Lift snippets etc. A thread recently started on the Jersey list btw...
http://n2.nabble.com/using-Lift-templates-with-Jersey-%28was-Re%3A--Jersey--custom--TemplateProcessor-not-having-its-constructor-injected-%29-td2675518.html

I've started hacking up a Jersey TemplateProcessor to wire in Lift
templates using implicit views; I can grab the template using Lift's
TemplateFinder fine - but I've just not got enough Lift implementation
knowledge yet to figure out how to render it :). I tried using
LiftServlet but thats a bit of a hack and it tends to just return the
template itself (since I'm not using Lifts mapping of URIs to requests
etc) - I kinda need to go in somewhere in between the two :)

FWIW I'm imagining two possible options

(i) folks write Java Resource Beans for JAXRS then wire Lift templates
using the @ImplictProvides mechanism to hook a resource bean to the
Lift template

(ii) folks create markup - or template instantiations within their
JAXRS beans written in Scala then there's no need for the
@ImplicitProvides hook. e.g.

@Path("/bar")
class MyResource {

@GET
@Produces(Array("text/html"))
def view() = <html><body><h1>Hello World!</h1></body></html>

...

@POST
def foo(form: SomeBean) = {...}
}

In either case, I need some little hook to be able to take a
Box[NodeSeq] and pass it to Lift to render it using the standard lift
tags + snippets etc.

This could be a gentle way to get folks gradually hooked on
Scala/Lift; gradually moving from Java/JSP to Scala/Lift for
templates, then resource beans etc. (Changing web frameworks is often
a big decision to make, though switching out JSP and using Lift
templates is a kinda no brainer... :)

I wondered if any Lift ninja's could give me some hints at a clean way
to do this?

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

David Pollak

unread,
Apr 22, 2009, 12:04:09 PM4/22/09
to lif...@googlegroups.com
James,

This is an interesting idea that more than one person has expressed excitement about.  Jorge Ortiz (one of the Lift committers) was puttering around with the separation of Lift's templating from the rest of Lift.  Personally, I think it's a pretty daunting task because a lot of the ways that Lift looks for templates and does its wiring and looks for snippets and generally re-writes the XML (e.g., to insert the Comet JavaScript), is woven tightly with the rest of Lift (e.g., LiftRules, LiftSession, etc.)

I am in favor of something like this happening, but I really think it's non-trivial.

Perhaps... just perhaps... we could do something where we put Java wrappers around some of the Lift-isms and use Lift as Filter in Java apps.  If you'd care to fork the Lift repository on GitHub and recruit a few others to help you, this could be an interesting side-project that, if successful, I could see as part of the main Lift distribution.

Thanks,

David
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Timothy Perrett

unread,
Apr 22, 2009, 12:14:26 PM4/22/09
to lif...@googlegroups.com

Just to emphasise this: I tried to decouple some of the templating stuff
previously and it was difficult to the point that I stopped bothering (jorge
was helping too)

By all means, id love to see this work, but it would be a quite a task and
one that involves knowing exactly how lift template pipeline works - good
luck!

Tim

James Strachan

unread,
Apr 22, 2009, 12:16:14 PM4/22/09
to lif...@googlegroups.com
2009/4/22 David Pollak <feeder.of...@gmail.com>:

> James,
>
> This is an interesting idea that more than one person has expressed
> excitement about.  Jorge Ortiz (one of the Lift committers) was puttering
> around with the separation of Lift's templating from the rest of Lift.
> Personally, I think it's a pretty daunting task because a lot of the ways
> that Lift looks for templates and does its wiring and looks for snippets and
> generally re-writes the XML (e.g., to insert the Comet JavaScript), is woven
> tightly with the rest of Lift (e.g., LiftRules, LiftSession, etc.)
>
> I am in favor of something like this happening, but I really think it's
> non-trivial.
>
> Perhaps... just perhaps... we could do something where we put Java wrappers
> around some of the Lift-isms and use Lift as Filter in Java apps.  If you'd
> care to fork the Lift repository on GitHub and recruit a few others to help
> you, this could be an interesting side-project that, if successful, I could
> see as part of the main Lift distribution.

Cool thanks.

BTW I don't much mind about ripping the template stuff out of Lift
into a separate piece - I am totally happy to have
LiftRules/LiftSession, Comet et al there and to keep Lift intact.

I guess all I really want is a way to render a NodeSeq which can
contain <lift:surround> and other arbitrary snippets inside. So all I
really want is another entry point into Lift other than the
filter/servlet where somehow I can do something like this...

LiftServlet.render(xhtml:NodeSeq, out:OutputStream)

which delves into the internal Lift stuff I don't grok in between
LiftServlet and TemplateFinder and does all that cool magic :) I could
pass in a servletRequest/response too if that'd help make the
implementation easier. I realise this could be tricky though with all
that ajax stuff etc.

David Pollak

unread,
Apr 22, 2009, 1:10:30 PM4/22/09
to lif...@googlegroups.com

Would:

LiftServlet.render(xhtml:NodeSeq, httpRequest: HttpServletRequest): LiftResponse

work along with helper methods to stream a LiftResponse out to an OutputStream work?
 


which delves into the internal Lift stuff I don't grok in between
LiftServlet and TemplateFinder and does all that cool magic :) I could
pass in a servletRequest/response too if that'd help make the
implementation easier. I realise this could be tricky though with all
that ajax stuff etc.


--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/


James Strachan

unread,
Apr 22, 2009, 2:43:01 PM4/22/09
to lif...@googlegroups.com
2009/4/22 David Pollak <feeder.of...@gmail.com>:

That would be perfect, yes please! :)

David Pollak

unread,
May 12, 2009, 8:30:45 PM5/12/09
to lif...@googlegroups.com
Please see:

S.render(NodeSeq, HttpServletRequest): NodeSeq

Thanks,

David

James Strachan

unread,
May 14, 2009, 3:55:14 AM5/14/09
to lif...@googlegroups.com
2009/5/13 David Pollak <feeder.of...@gmail.com>:

> Please see:
>
> S.render(NodeSeq, HttpServletRequest): NodeSeq

Awesome - huge thanks! :)

I was just about to post a patch I'd figured out to implement this in
a way less elegant way; you saved me the trouble :)

I've managed to use this API to provide a basic integration of Lift
templates and Jersey....
http://github.com/jstrachan/liftweb/tree/master/lift-jersey

I'm still working on it to provide some better examples (and
navigation isn't quite working yet), but so far its working pretty
well!

David Pollak

unread,
May 14, 2009, 11:52:28 AM5/14/09
to lif...@googlegroups.com
On Thu, May 14, 2009 at 12:55 AM, James Strachan <james.s...@gmail.com> wrote:

2009/5/13 David Pollak <feeder.of...@gmail.com>:
> Please see:
>
> S.render(NodeSeq, HttpServletRequest): NodeSeq

Awesome - huge thanks! :)

I was just about to post a patch I'd figured out to implement this in
a way less elegant way; you saved me the trouble :)

I've managed to use this API to provide a basic integration of Lift
templates and Jersey....
http://github.com/jstrachan/liftweb/tree/master/lift-jersey

I'm still working on it to provide some better examples (and
navigation isn't quite working yet), but so far its working pretty
well!

Cool.  Are you involved with Dan Kulp in your JAXRS work?


--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/


James Strachan

unread,
May 15, 2009, 5:44:16 AM5/15/09
to lif...@googlegroups.com
2009/5/14 David Pollak <feeder.of...@gmail.com>:

>
>
> On Thu, May 14, 2009 at 12:55 AM, James Strachan <james.s...@gmail.com>
> wrote:
>>
>> 2009/5/13 David Pollak <feeder.of...@gmail.com>:
>> > Please see:
>> >
>> > S.render(NodeSeq, HttpServletRequest): NodeSeq
>>
>> Awesome - huge thanks! :)
>>
>> I was just about to post a patch I'd figured out to implement this in
>> a way less elegant way; you saved me the trouble :)
>>
>> I've managed to use this API to provide a basic integration of Lift
>> templates and Jersey....
>> http://github.com/jstrachan/liftweb/tree/master/lift-jersey
>>
>> I'm still working on it to provide some better examples (and
>> navigation isn't quite working yet), but so far its working pretty
>> well!
>
> Cool.  Are you involved with Dan Kulp in your JAXRS work?

I work with Dan and know him well; but I hack on Jersey - I don't work on CXF.

Reply all
Reply to author
Forward
0 new messages