You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Jurgen Lust <jl...@apache.org> on 2007/06/28 21:57:53 UTC

Renderkit using Freemarker templates

Hi,

I think most people will agree that writing Renderers for JSF components
using the standard tools, i.e. ResponseWriter.startElement and
ResponseWriter.writeAttribute etc., is not very straightforward or
productive, especially when creating complex components. If you take a
look at org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer,
you'll know what I mean :)

One of the great things about Dojo is that you can create templates for
your components. Inspired by this, I tried to do something similar for
JSF renderers, using Freemarker. I put it in the sandbox, and wrote a
replacement HtmlOutputTextRenderer based on it. I know the outputText is
a bad example for this, but for complex stuff, this could be really
useful.

What do you think?

Jurgen

RE: Renderkit using Freemarker templates

Posted by "Kito D. Mann" <km...@virtua.com>.
Hmmmm... I presented something similar to this at JavaOne (called
"intuition"), except that it focuses more on component creation (although
the render kit part is just a step further). I was talking to Jacob Hookom
about including it in Facelets, since it uses Facelets for the template
(although that's not required). He wasn't terribly interested, though, so I
haven't quite figured out where it should go...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann - Author, JavaServer Faces in Action
http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info

* Sign up for the JSF Central newsletter!
http://oi.vresp.com/?fid=ac048d0e17 *


> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
> Sent: Friday, June 29, 2007 4:51 PM
> To: dev@myfaces.apache.org
> Subject: Re: Renderkit using Freemarker templates
> 
> The performance question is a good one, but I thought I'd throw
> something else into the discussion... I've thought about creating
> something like this a number of times, as a way to make components more
> flexible for the user.
> 
> When a component has more complex rendering, I often find I'd like to
> be
> able to tweak the generated HTML in ways that simply aren't possible
> without replacing the renderer. If the renderer was driven by a
> template
> *and* there was a supported mechanism for specifying a custom template
> (on a per-component-use basis or even just on a per-application basis),
> this would be much easier.
> 
> On the other hand, the potential for people breaking the component by
> changing the render template in unexpected ways is a little
> unsettling...
> 
> L.
> 
> Adam Winer wrote:
> > When I've thought of this, I've always imagined that
> > really complex renderers would end up requiring
> > Java code, and that really simple renderers, well,
> > aren't that hard to write in the first place, and would be
> > much slower when written that way.  At that point,
> > I gave up and worked on things I was sure would work. :)
> >
> > Templating a la Facelets has seemed like a pretty
> > good middle ground for assembling on-the-fly
> > components.
> >
> > That said, I'd be absolutely thrilled to proven wrong!
> > So I guess two questions:
> >  - Have you had a chance to benchmark the Freemarker-coded
> >    outputText against the one in MyFaces?
> >  - Any chance of tackling a complex component so we could
> >   see what it looks like?
> >
> > -- Adam
> >
> >
> >
> > On 6/28/07, Jurgen Lust <jl...@apache.org> wrote:
> >> Hi,
> >>
> >> I think most people will agree that writing Renderers for JSF
> components
> >> using the standard tools, i.e. ResponseWriter.startElement and
> >> ResponseWriter.writeAttribute etc., is not very straightforward or
> >> productive, especially when creating complex components. If you take
> a
> >> look at
> org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer,
> >> you'll know what I mean :)
> >>
> >> One of the great things about Dojo is that you can create templates
> for
> >> your components. Inspired by this, I tried to do something similar
> for
> >> JSF renderers, using Freemarker. I put it in the sandbox, and wrote
> a
> >> replacement HtmlOutputTextRenderer based on it. I know the
> outputText is
> >> a bad example for this, but for complex stuff, this could be really
> >> useful.
> >>
> >> What do you think?
> >>
> >> Jurgen
> >>
> >


Re: Renderkit using Freemarker templates

Posted by Laurie Harper <la...@holoweb.net>.
The performance question is a good one, but I thought I'd throw 
something else into the discussion... I've thought about creating 
something like this a number of times, as a way to make components more 
flexible for the user.

When a component has more complex rendering, I often find I'd like to be 
able to tweak the generated HTML in ways that simply aren't possible 
without replacing the renderer. If the renderer was driven by a template 
*and* there was a supported mechanism for specifying a custom template 
(on a per-component-use basis or even just on a per-application basis), 
this would be much easier.

On the other hand, the potential for people breaking the component by 
changing the render template in unexpected ways is a little unsettling...

L.

Adam Winer wrote:
> When I've thought of this, I've always imagined that
> really complex renderers would end up requiring
> Java code, and that really simple renderers, well,
> aren't that hard to write in the first place, and would be
> much slower when written that way.  At that point,
> I gave up and worked on things I was sure would work. :)
> 
> Templating a la Facelets has seemed like a pretty
> good middle ground for assembling on-the-fly
> components.
> 
> That said, I'd be absolutely thrilled to proven wrong!
> So I guess two questions:
>  - Have you had a chance to benchmark the Freemarker-coded
>    outputText against the one in MyFaces?
>  - Any chance of tackling a complex component so we could
>   see what it looks like?
> 
> -- Adam
> 
> 
> 
> On 6/28/07, Jurgen Lust <jl...@apache.org> wrote:
>> Hi,
>>
>> I think most people will agree that writing Renderers for JSF components
>> using the standard tools, i.e. ResponseWriter.startElement and
>> ResponseWriter.writeAttribute etc., is not very straightforward or
>> productive, especially when creating complex components. If you take a
>> look at org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer,
>> you'll know what I mean :)
>>
>> One of the great things about Dojo is that you can create templates for
>> your components. Inspired by this, I tried to do something similar for
>> JSF renderers, using Freemarker. I put it in the sandbox, and wrote a
>> replacement HtmlOutputTextRenderer based on it. I know the outputText is
>> a bad example for this, but for complex stuff, this could be really
>> useful.
>>
>> What do you think?
>>
>> Jurgen
>>
> 


Re: Renderkit using Freemarker templates

Posted by Werner Punz <we...@gmail.com>.
Adam Winer schrieb:
> When I've thought of this, I've always imagined that
> really complex renderers would end up requiring
> Java code, and that really simple renderers, well,
> aren't that hard to write in the first place, and would be
> much slower when written that way.  At that point,
> I gave up and worked on things I was sure would work. :)
> 

Well depends, I think the Turbine framework has found a good middle 
ground (they work extensively with velocity)
they add some tools classes and you can add your own, and the basic
action controllers just push data objects into the templates.
So you end up with a predefined set of tools in the template
and one or more data objects.
This could work very well for a template based component model.

As for the speed, it is probably a question on which level you can 
trigger the templates.
Templating engines usually do some compilation and caching and build 
their own page tree, so you might (like facelets) gain even a lot of 
speed if done right, due to better caching than pure jsp which runs 
straight through the rendering code every time.

I dont think you can gain this speed alone on component level (you might 
gain some if you can intercept the caching points properly) you really 
have to do the entire rendering on page level that way.

Facelets basically does this right as far as I understood but they did 
it by sacrificing jsp (not a bad decision)


Re: Renderkit using Freemarker templates

Posted by Adam Winer <aw...@gmail.com>.
When I've thought of this, I've always imagined that
really complex renderers would end up requiring
Java code, and that really simple renderers, well,
aren't that hard to write in the first place, and would be
much slower when written that way.  At that point,
I gave up and worked on things I was sure would work. :)

Templating a la Facelets has seemed like a pretty
good middle ground for assembling on-the-fly
components.

That said, I'd be absolutely thrilled to proven wrong!
So I guess two questions:
  - Have you had a chance to benchmark the Freemarker-coded
    outputText against the one in MyFaces?
  - Any chance of tackling a complex component so we could
   see what it looks like?

-- Adam



On 6/28/07, Jurgen Lust <jl...@apache.org> wrote:
> Hi,
>
> I think most people will agree that writing Renderers for JSF components
> using the standard tools, i.e. ResponseWriter.startElement and
> ResponseWriter.writeAttribute etc., is not very straightforward or
> productive, especially when creating complex components. If you take a
> look at org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer,
> you'll know what I mean :)
>
> One of the great things about Dojo is that you can create templates for
> your components. Inspired by this, I tried to do something similar for
> JSF renderers, using Freemarker. I put it in the sandbox, and wrote a
> replacement HtmlOutputTextRenderer based on it. I know the outputText is
> a bad example for this, but for complex stuff, this could be really
> useful.
>
> What do you think?
>
> Jurgen
>

Re: Renderkit using Freemarker templates

Posted by Werner Punz <we...@gmail.com>.
Jurgen Lust schrieb:
> Hi,
> 
> I think most people will agree that writing Renderers for JSF components
> using the standard tools, i.e. ResponseWriter.startElement and
> ResponseWriter.writeAttribute etc., is not very straightforward or
> productive, especially when creating complex components. If you take a
> look at org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer,
> you'll know what I mean :)
> 
> One of the great things about Dojo is that you can create templates for
> your components. Inspired by this, I tried to do something similar for
> JSF renderers, using Freemarker. I put it in the sandbox, and wrote a
> replacement HtmlOutputTextRenderer based on it. I know the outputText is
> a bad example for this, but for complex stuff, this could be really
> useful.
> 
> What do you think?
> 
> Jurgen
> 
Actually Sorin is working on it as reported.

As I said before this would be heavens sent, the renderer part of the 
components really should be on the markup not vice versa.

The main problem I see if you do something like that is that you 
probably have to do it in the context of a page, request or session 
singleton
on component level it would be a huge speed hit, on the other hand if 
you can do it on page/session or application level you even could gain 
speed due to the caching those engines do.

(They work very similarily in the way that they build and compile a tree 
and do the caching within the tree)
I have seen things done in velocity (and freemarker is pretty similar) 
on pagelevel which outperform pure jsp by miles.

The main issue is on the renderer side, you have to push into the template:

a) your component object
b) a set of tools classes every component should be able to access, 
which provided some services


Re: Renderkit using Freemarker templates

Posted by Sorin Silaghi <so...@gmail.com>.
That is a nice idea ... I'm actually doing it for GSoC :) ... I haven't got
too far because I never wrote a renderkit before but I'm planning on writing
renderers this way for all basic myfaces components and the tomahawk ones as
well ...

http://code.google.com/soc/asf/appinfo.html?csaid=FE280ED4B49C1166

I'll take a look at what you've put in the sandbox ... It will probably help
allot..

On 6/29/07, Catalin Kormos <ca...@gmail.com> wrote:
>
>
>
> ---------- Forwarded message ----------
> From: Jurgen Lust < jlust@apache.org>
> Date: Jun 28, 2007 9:57 PM
> Subject: Renderkit using Freemarker templates
> To: dev@myfaces.apache.org
>
> Hi,
>
> I think most people will agree that writing Renderers for JSF components
> using the standard tools, i.e. ResponseWriter.startElement and
> ResponseWriter.writeAttribute etc., is not very straightforward or
> productive, especially when creating complex components. If you take a
> look at org.apache.myfaces.custom.schedule.ScheduleDetailedDayRenderer ,
> you'll know what I mean :)
>
> One of the great things about Dojo is that you can create templates for
> your components. Inspired by this, I tried to do something similar for
> JSF renderers, using Freemarker. I put it in the sandbox, and wrote a
> replacement HtmlOutputTextRenderer based on it. I know the outputText is
> a bad example for this, but for complex stuff, this could be really
> useful.
>
> What do you think?
>
> Jurgen
>