You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by Bob Schellink <sa...@gmail.com> on 2010/02/13 03:02:20 UTC

v.2.2.0 development notes

Hi all,

Just a quick note on the development front. I've created a branch for v2.1.0[1] which we can 
maintain for bug fix releases. New development for v2.2.0 will occur in trunk.

Our current roadmap can be seen here[2]. We have 13 tasks in JIRA targeting v2.2.0, which includes 
revamping the Menu control.

For 2.2.0 I'd also like to see improved Ajax support in the core framework. Since Ajax is a major 
feature I'll write up some proposals on the wiki and post a message here to stimulate further 
discussions.

kind regards

bob

[1]: http://svn.apache.org/repos/asf/click/branches/click-2.1.0/
[2]: 
https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&mode=hide&sorter/order=DESC&sorter/field=priority&resolution=-1&pid=12310902&fixfor=12314164

Re: v.2.2.0 development notes

Posted by Bob Schellink <sa...@gmail.com>.
On 15/02/2010 09:10 AM, Finn Bock wrote:
> Another question.
>
> 1) How do I pass request parameters into the ajax call (like a
> database id param) and will the parameter be bound to the @Bindable.


I can currently see two ways to pass parameters.

1. Set attributes on the Control and use JavaScript to grab these parameters at runtime. For example 
a link control exposes parameters that are rendered as part of the href attribute. The Javascript 
can grab these parameters and pass them back to the server.

The following attributes can be checked: src, href, action.

2. The Behavior object can expose a map of parameters for adhoc parameters. The parameter map can be 
rendered in the behavior template:

Page.java

   behavior.addParameter("id", student.getId());

template.js:
   $.ajax( ..., $parameters + '&' + $controlParams, ...);


> That means that the java API that I use in my application depends on
> the javascript framework? If that is the case: yuck.


I suppose if there are enough compatibility between the different frameworks then a simple common 
API can be exposed. For example Partial.replace could map to element.innerHTML as an example.

A common API is something to keep in mind, but I don't really know what that API would look like. Of 
course if anybody wants to design such an API that would be great.

In the meantime we could keep the Partial API lean and refactor it later as the implementation takes 
shape. For example the JQuery Taconite implementation has a fair bit of methods which are supported 
by jQuery:

http://clickclick.googlecode.com/svn/trunk/site/javadoc/jquery-api/net/sf/clickclick/jquery/Taconite.html#APPEND

When we have a Prototype implementation we could move some of those methods to Partial if it is 
supported by both frameworks.

> Yes, when taconite is used, the target control is named together with
> the new content and that is IMO as it should be. I just think that a
> simple replace should be part of the Partial interface and not depend
> on my choice of JQuery as the framework.


Yep, see my comment above.


> How would the choice of framework version be controlled? or put
> another way how could I made AjaxBehavior use the same version of
> JQuery that the rest of my application uses?


Good question. We could expose some static methods or a property file to specify the jQuery version. 
However changing the jQuery version might break plugin dependencies, so Behaviors should clearly 
document the minimum jQuery version supported. This is what most jQuery plugins do as well.

kind regards

bob

Re: v.2.2.0 development notes

Posted by Finn Bock <bc...@gmail.com>.
2010/2/14 Bob Schellink <sa...@gmail.com>:
> Hi Finn,
>
> Thanks for your thorough review. ...

You are welcome, and thank you for your answers.

Another question.

1) How do I pass request parameters into the ajax call (like a
database id param) and will the parameter be bound to the @Bindable.


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

That is good.

> ...
>
>> 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 have plugins for taconite though.
>
> From Click's perspective it only knows about the Partial object that it
> streams back to the client. Whether a Partial implementation supports
> multiple DOM updates will be determined by the client-side technology used.

That means that the java API that I use in my application depends on
the javascript framework? If that is the case: yuck.


>> 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 specify the target.

Yes, when taconite is used, the target control is named together with
the new content and that is IMO as it should be. I just think that a
simple replace should be part of the Partial interface and not depend
on my choice of JQuery as the framework.


How would the choice of framework version be controlled? or put
another way how could I made AjaxBehavior use the same version of
JQuery that the rest of my application uses?

regards,
Finn

Re: v.2.2.0 development notes

Posted by Bob Schellink <sa...@gmail.com>.
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 well 
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 to 
change the label:

   Source: 
http://code.google.com/p/clickclick/source/browse/trunk/clickclick/jquery-examples/src/net/sf/clickclick/examples/jquery/page/ajax/TextDemo.java

   Live Demo: http://clickclick-jquery.appspot.com/ajax/text-demo.htm

The JQActionLink control embeds a JQHelper object which includes all dependencies and a default JS 
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 different 
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 have 
plugins for taconite though.

 From Click's perspective it only knows about the Partial object that it streams back to the client. 
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 could 
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 taken 
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
     label.setId("labelId");

     AjaxBehavior behavior = new AjaxBehavior( JQueryEvent.KEYPRESS ) {

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

         // Copy field value
         copy.setValue(field.getValue());

         // Inform Taconite to replace copy field
         partial.replace(copy);

         return partial;
       }
     }

     f.addBehavior(behavior);
   }
}


> 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 specify 
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

bob

Re: v.2.2.0 development notes

Posted by Finn Bock <bc...@gmail.com>.
Bob Schellink <sa...@gmail.com>:
>
> I've put together some proposals for improving Ajax support:
>
>  http://cwiki.apache.org/confluence/display/CLICK/Ajax+Proposals
>
> If you have any suggestions or questions let me know.

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");


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.


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


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



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 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.

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

regards,
Finn

Re: v.2.2.0 development notes

Posted by Bob Schellink <sa...@gmail.com>.
On 13/02/2010 01:02 PM, Bob Schellink wrote:
>
> For 2.2.0 I'd also like to see improved Ajax support in the core
> framework. Since Ajax is a major feature I'll write up some proposals on
> the wiki and post a message here to stimulate further discussions.


I've put together some proposals for improving Ajax support:

   http://cwiki.apache.org/confluence/display/CLICK/Ajax+Proposals

If you have any suggestions or questions let me know.

kind regards

bob