[ 
https://issues.apache.org/jira/browse/WICKET-5087?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13598714#comment-13598714
 ] 

Martin Grigorov commented on WICKET-5087:
-----------------------------------------

@Igor: I guess by "this" you mean AbstractDefaultAjaxBehavior#getShortUrl() 
which is used by AjaxShortUrlBehavior. 
I'm sure that my implementation is not the optimal one and that's why I started 
the discussion at dev@.

If you remember a talk between me, you and Peter Ertl in IRC around an year ago 
- Peter asked for a method in Wicket JS API that will make it easier to request 
a behavior by some stable identifier (e.g. a nice looking url). 
Lately I see that Ernesto struggles to do something similar:
- first, in his attempt to make Select2 Wicket component stateless
- and second, in his Wicket-AngularJS integration

In both he needs to make an ajax request from some .js logic to Wicket to 
return some JSON data. And the problem is that he has to store somewhere the 
ajax behavior callback url to be able to use it later.
With this ticket I try to find a way to make this simpler - anywhere in .js 
code one could use: Wicket.Ajax.method({su: 'some/nice/url', /* other 
attributes */ }) and this should call the respective behavior at the server 
side as with the normal callback url.

If it was only for Ajax behaviors then the logic can be easily encapsulated in 
AbstractDefaultAjaxBehavior#renderHead(): a DomReadyHeaderItem can add a 
mapping "short/stable url -> original callbackUrl" and then before making the 
Ajax call Wicket.Ajax.doAjax() will check whether attrs.u has an entry in this 
mapping and use the long version.

I tried to make this functionality available for non-ajax behaviors as well and 
that's why AjaxShortUrlBehavior is introduced and it uses a visitor to find the 
"endpoint". Actually I see this working for any IRequestListener - for example 
the JS client can make a request to IResourceListener or IBehaviorListener, and 
the listener can return any kind of data which can be handled with a success 
handler. 

@All: do you find this feature useful at all ?
                
> Make it easier to request (ajax)behaviors by name from JavaScript
> -----------------------------------------------------------------
>
>                 Key: WICKET-5087
>                 URL: https://issues.apache.org/jira/browse/WICKET-5087
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>    Affects Versions: 6.6.0
>            Reporter: Martin Grigorov
>            Assignee: Martin Grigorov
>         Attachments: WICKET-5087.patch, wicket-ajax-shorturl.tgz
>
>
> Many JavaScript libraries require server endpoint for making requests for 
> loading/saving data.
> To integrate such JS library with Wicket the application developer should 
> make the IRequestListener's url available as an endpoint. That is it need to 
> store somewhere the url produced by #urlFor() or 
> AjaxBehavior#getCallbackUrl().
> This new feature will make this much simpler for the application developer.
> A new method will be added to Wicket.Ajax namespace to facilitate this:
>    Wicket.Ajax.short({
>       'su': 'countries',
>       'dep': [function() {return [{'name': 'extra', 'value': 'param'}]}],
>       'coh': [function() {console.log('Completed!')}]
>     });
> This new method will again receive an object with all possible attributes 
> plus a new one - 'su', stands for 'short/stable/simple' url.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to