You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Jeremy Thomerson (JIRA)" <ji...@apache.org> on 2009/04/27 01:20:30 UTC

[jira] Updated: (WICKET-1651) Extension Points for AutoComplete

     [ https://issues.apache.org/jira/browse/WICKET-1651?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeremy Thomerson updated WICKET-1651:
-------------------------------------

    Fix Version/s:     (was: 1.4-RC3)
                   1.4-RC4

> Extension Points for AutoComplete
> ---------------------------------
>
>                 Key: WICKET-1651
>                 URL: https://issues.apache.org/jira/browse/WICKET-1651
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-extensions
>    Affects Versions: 1.4-M1
>            Reporter: Roland Huss
>            Assignee: Johan Compagner
>             Fix For: 1.4-RC4
>
>         Attachments: initHead.patch, javascript.patch
>
>
> I'm working on an extension of AutoCompleteTextField for
> wicket-extensions for selecting objects and remembering their identity
> in the model, as described in this previous thread
> http://www.mail-archive.com/wicket-dev@incubator.apache.org/msg02820.html
> (it avoids the semantic problems described there by changing to a
> readonly view as soon as the object has been selected).
> This extension, which I would like to contribute to wicketstuff,
> reuses most of the existing functionality of the wicket-extension
> autocomlete feature. However, in order to avoid massive code
> duplication a trivial and non-intrusive extension point in
> AbstractAutoCompleteBehaviour is required. Here's the diff, it simply
> puts on the initiaization stuff into an overwritable, unique
> initHead() method which is called from within renderHead(). So
> instead:
> {code}
>    public void renderHead(IHeaderResponse response)
>    {
>         super.renderHead(response);
>         response.renderJavascriptReference(AUTOCOMPLETE_JS);
>         ...
>     }
> {code}
> I need
> {code}
>     public void renderHead(IHeaderResponse response)
>     {
>         super.renderHead(response);
>         initHead(response);
>     }
>     protected void initHead(IHeaderResponse response) {
>         response.renderJavascriptReference(AUTOCOMPLETE_JS);
>         ...
>     }
> {code}
> The reason is obvious: I need to overwrite this to include my own
> extended Javascript but I also need a call to super.renderHead().
> In addition, I modified wicket-autocomplete.js, so that the
> Wicket.AutoComplete Javascript object is subclassable (needs also only
> a handful of changes).  The patch make three methods overridable by assigning 
> it as 'member' methods (instead of being static methods). These are updateValue()
> (introduced for updating the selected value), getSelectedValue() and
> getSelectedElement() also introduced for being accesible in a
> subclass). As you can see the patch is rather minimal and allows
> simple subclasses like:
> {code}
> Wicketstuff.ObjectAutoComplete=function(elementId, objectElementId, callbackUrl, cfg){
>     Wicket.AutoComplete.call(this,elementId,callbackUrl,cfg);
>     this.updateValue = function() {
>         var objElement = wicketGet(objectElementId);
>         var textElement = wicketGet(elementId);
>         var selected = this.getSelectedValue();
>         objElement.value = selected['idvalue'];
>         textElement.value = selected['textvalue'];
>     }
>     this.getSelectedValue = function() {
>         var element= this.getSelectedElement();
>         var attr = element.attributes['textvalue'];
>         var idAttr = element.attributes['idvalue'];
>         var value;
>         if (attr == undefined) {
>             value = element.innerHTML;
>         } else {
>             value = attr.value;
>         }
>         return { 'textvalue': value.replace(/<[^>]+>/g,""), 'idvalue' : idAttr.value };
>     }
> }
> // Inherit without calling constructor of Wicket.AutoComplete
> //
> var tmpClass = function() {};
> tmpClass.prototype = Wicket.AutoComplete.prototype;
> Wicketstuff.ObjectAutoComplete.prototype = new tmpClass();
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.