webtier@glassfish.java.net

Re: [webtier] Rendering of javascript on[click|change|*] event handlers

From: Jim Driscoll <Jim.Driscoll_at_Sun.COM>
Date: Sat, 11 Jul 2009 02:25:56 -0700

On 7/11/09 12:15 AM, webtier_at_javadesktop.org wrote:
> I am often working with frontend developers saying, they would not like to introduce JSF into a project because of rendering of components. Indeed some of the more complex components have renderers that produce very "oldschool" or deprecated html (nested tables is a common example). Well, if you can abandon the usage of these components... no problem at all.

Sadly, the spec is pretty clear about how those tags should be rendered,
so there's little we can do without badly breaking existing code. But
yeah, I feel the same twinge of annoyance every time I see that.

> But there is one point with the introduction of partial page rendering also affecting all the default components. Most of the frontend developers agree on the design principle that event handlers as part of the solution for asynchronous request should not be rendered directly on the tags itself's, but rather in an inline javascript part in the html or a separate javavscript file, that binds the event handlers to the tag element.

So, you want to inject event listeners into the page, separated from the
tags whose events they'll intercept? Um, ok. That seems to be taking
separation of concerns too far, IMO, but ok - if that's what your
designer insist upon, then I guess you've got little choice. Let me
know if that's not what you're advocating. BTW - that doesn't work too
portably in different browsers, does it? IE's totally different than
anyone else, even more than usual.

> To cut a long story short: Is it possible to modificate the rendering of some tag attributes without rewriting a complete renderer for all components? I would like to relocate the output of the ScriptRenderer into a single location and bind the event handlers either using hand written wiring code or using a common javascript framework like YUI or JQuery.

Sure, if you're able to modify the source code to Mojarra, it's easy.
Otherwise, not so easy, without modifying all of the rendering
components (which is about 10 or so, it's not an impossible task). In
Mojarra, just find RenderKitUtils, and find the renderOnchange and
renderOnclick methods... It should be a relatively simple thing to
cache the information instead of outputting it right then, then flushing
it to the page when closing the document. Tracing the codepath from
something like renderOnchange is pretty hard, but if you're assuming no
additional added behaviors, you should be able to shortcircuit out of
that without too much pain - most of the extra stuff in there is to
allow for new added behaviors.

Jim



Jim Driscoll

> Thanks in advance,
>
> Sven Linstaedt
> [Message sent by forum member 'tzwoenn' (tzwoenn)]
>
> http://forums.java.net/jive/thread.jspa?messageID=355217
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>