click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <>
Subject Re: v.2.2.0 development notes
Date Sun, 14 Feb 2010 04:22:14 GMT
Hi Finn,

Thanks for your thorough review. Comments inline.

On 14/02/2010 08:35 AM, Finn Bock wrote:
> It is good to see that ajax will get some attention. I have a few questions:
> 1) My guess is that the inclusion of my-page.js does not happen
> automatically. I will have to add it in onInit or the page ctor:
>           getHeadElements().add(new JsImport("/mycorp/js/my-page.js");

For #1 yes, Click provides a way to invoke a page method and nothing more. It turns the Page
into a 
Controller with methods that the browser can invoke. While simple and mechanic it could work
for adhoc GET requests.

For #2 or #3 the Control/Behavior can include its dependencies, including a default JS template.

ClickClick is based on #2 and you can see from the example below only Java code is necessary
change the label:


   Live Demo:

The JQActionLink control embeds a JQHelper object which includes all dependencies and a default
Velocity template. The template is JavaScript/jQuery code that can be customized if needed.

ClickClick has three Helpers that extend JQHelper and uses different templates to perform
operations. To give you an idea there is a helper for forms, auto complete and polling.

> 2) In the "1. Ajax aware Page methods" proposal you write that no
> other page event methods will be called, but I think some kind of
> security check will be needed, so onSecurityCheck() should perhaps be
> called.

Yes you are right, onSecurityCheck should still be fired. I've updated the WIKI.

> 3) What does the "click" string passed to the AjaxBehaviour ctor mean.
> Is it the event that is bound to in jquery?

Yes it is the event. We could make the event argument optional and let the Behavior define
a default 
event it will bind to.

> 4) How does it handle multiple dom updates? Taconite?

For jQuery I think the taconite plugin is pretty good. I'm not sure if other JS frameworks
plugins for taconite though.

 From Click's perspective it only knows about the Partial object that it streams back to the
Whether a Partial implementation supports multiple DOM updates will be determined by the client-side

technology used.

> My reaction so far:
> I feel somewhat put off by the suggestion that even the simplest ajax
> example requires that I write javascript. Even more so when the
> javascript isn't easy to maintain:
> a) id's must match between java and javascript.
> b) duplicate target id (mylink in the example)
> c) hardcode url of the page in javascript.

I've not done a good job explaining this in the proposal, but the example JavaScript code
is what a 
jQuery based implementation should *generate*. Here is what a generic jquery based template
look like:

// $selector is a variable passed to the template from Click
$('$selector').bind('$event', makeRequest);

function makeRequest(event) {

   //grab ID parameter from the element which is passed to server
   var sourceId = $(this).getAttribute("id");

   // $path is passed to the template from Click
   $.get("$path", {
     sourceId: 1, // Parameter 1      -> ID of element event occurred on
     event: event.type // Parameter 2 -> Event that was fired

If jQuery's Taconite is used, there is no need for a "success" JS handler here, it will be
care of by the Partial response:

public class MyPage {

   private Field field = new TextField("field");
   private Field copy = new TextField("copy");

   public void onInit() {

     // Label will be the target. The ID is defined only once

     AjaxBehavior behavior = new AjaxBehavior( JQueryEvent.KEYPRESS ) {

       public Partial onEvent(Control source, Event event) {
         // Taconite extends Partial
         Taconite partial = new Taconite();

         // Copy field value

         // Inform Taconite to replace copy field

         return partial;


> I think the target dom (or control) element(s) must be named when the
> partial is created, otherwise it is too hard to read and understand an
> ajax click application.

Could you expand on this? I would imagine that if Taconite is used it won't be necessary to
the target.

> As far as I understand the proposals, I favor #3 without support for
> #1. #1 is too simple IMO.

Noted we could leave #1 out, however #1 could be useful for normal (non-ajax) requests as
well though.

Hope this clears the issues raised. I'd really like to get this Ajax stuff right so keep the

comments coming.

kind regards


View raw message