textField.setOnKeyUp("javascript:autoCompleteUpdateValueField('" + textField.getId() + "', '" + TYPING_VALUE + "');");
textField.setOnKeyDown("javascript:autoCompleteKeyDownHandler(event, '" + textField.getId() +"');"); textField.setOnKeyUp("javascript:autoCompleteKeyUpHandler(event, '" + textField.getId() + "', '" + TYPING_VALUE + "');");
    protected Layout getLayout(Object object, Class type) {        return new Layout() {            @Override            public HtmlComponent createComponent(Object object, Class type) {                                HtmlInlineContainer container = new HtmlInlineContainer();                addScripts(container);                                MetaSlotKey key = (MetaSlotKey) getContext().getMetaObject().getKey();                                HtmlHiddenField valueField = new HtmlHiddenField();                valueField.setTargetSlot(key);                valueField.setId(key.toString() + "_AutoComplete");                valueField.setName(valueField.getId());                container.addChild(valueField);                valueField.setConverter(new AutoCompleteConverter(getClassName()));                                HtmlTextInput textField = new HtmlTextInput();                textField.setId(key.toString());                textField.setName(textField.getId());                textField.setClasses(getTextFieldStyleClass());                textField.setSize(getSize());                textField.setOnKeyUp("javascript:autoCompleteUpdateValueField('" + textField.getId() + "', '" + TYPING_VALUE + "');");                container.addChild(textField);                if (getRawSlotName() != null) {                    textField.setController(new UpdateRawNameController(getRawSlotName()));                }                                HtmlBlockContainer resultsContainer = new HtmlBlockContainer();                resultsContainer.setId(key.toString() + "_div");                resultsContainer.setClasses(getAutoCompleteStyleClass());                container.addChild(resultsContainer);                                addFinalScript(container, textField.getId(), resultsContainer.getId());                                return container;            }            private void addScripts(HtmlInlineContainer container) {                HttpServletRequest request = getContext().getViewState().getRequest();                                if (request.getAttribute(SCRIPT_FLAG_KEY) != null) {                    return;                }                                request.setAttribute(SCRIPT_FLAG_KEY, true);                                HtmlLink link = new HtmlLink();                link.setModuleRelative(false);                link.setContextRelative(true);                                String[] scriptNames = new String[] {                         "prototype.js",                         "effects.js",                         "dragdrop.js",                         "controls.js",                         "fenixScript.js"                 };                                for (String script : scriptNames) {                    addSingleScript(container, link, script);                }            }            private void addSingleScript(HtmlInlineContainer container, HtmlLink link, String scriptName) {                link.setUrl("/javaScript/" + scriptName);                HtmlScript script = new HtmlScript("text/javascript", link.calculateUrl(), true);                container.addChild(script);            }            private void addFinalScript(HtmlInlineContainer container, String textFieldId, String divId) {                HtmlLink link = new HtmlLink();                link.setModuleRelative(false);                link.setContextRelative(true);                                link.setUrl(SERVLET_URI);                link.setParameter("serviceName", getServiceName());                link.setParameter("serviceArgs", getServiceArgs());                link.setParameter("labelField", getLabelField());                link.setParameter("valueField", "idInternal"); // TODO: allow configuration, needs also converter                link.setParameter("styleClass", getAutoCompleteItemsStyleClass() == null ? "" : getAutoCompleteItemsStyleClass());                link.setParameter("class", getClassName());                                if (getFormat() != null) {                    link.setParameter("format", getFormat());                }                                if (getMaxCount() != null) {                    link.setParameter("maxCount", String.valueOf(getMaxCount()));                }                                String finalUri = link.calculateUrl();                String scriptText = "new Ajax.Autocompleter('" + textFieldId + "','" + divId + "','" + finalUri +                        "', {paramName: 'value', afterUpdateElement: autoCompleteUpdate, minChars: " + getMinChars() + "});";                                HtmlScript script = new HtmlScript();                script.setContentType("text/javascript");                script.setScript(scriptText);                                container.addChild(script);            }        };    }