HttpServletRequest request = getContext().getViewState().getRequest();
    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()));                                HtmlHiddenField oldValueField = new HtmlHiddenField();                oldValueField.setId(key.toString() + "_OldValue");                oldValueField.setName(oldValueField.getId());                container.addChild(oldValueField);                                HtmlTextInput textField = new HtmlTextInput();                textField.setId(key.toString());                textField.setName(textField.getId());                textField.setClasses(getTextFieldStyleClass());                textField.setSize(getSize());                textField.setOnKeyDown("javascript:autoCompleteKeyDownHandler(event, '" + textField.getId() +"');");                textField.setOnKeyUp("javascript:autoCompleteKeyUpHandler(event, '" + textField.getId() + "', '" + TYPING_VALUE + "');");                container.addChild(textField);                if (getRawSlotName() != null) {                    textField.setController(new UpdateRawNameController(getRawSlotName()));                }                                HtmlInlineContainer loadingContainer = new HtmlInlineContainer();                loadingContainer.setId(key.toString() + "_Indicator");                loadingContainer.setStyle("display: none;");                HtmlText loadingText = new HtmlText(RenderUtils.getResourceString("fenix.renderers.autocomplete.loading"));                loadingContainer.addChild(loadingText);                                HtmlLink link = new HtmlLink();                link.setModuleRelative(false);                link.setUrl("/images/autocomplete/spinner.gif");                HtmlImage indicatorImage = new HtmlImage();                indicatorImage.setSource(link.calculateUrl());                loadingContainer.addChild(indicatorImage);                if (isIndicatorShown()) {                    container.addChild(loadingContainer);                }                HtmlText errorMessage = new HtmlText(RenderUtils.getResourceString("fenix.renderers.autocomplete.error"));                errorMessage.setId(key.toString() + "_Error");                errorMessage.setClasses(getErrorStyleClass());                errorMessage.setStyle("display: none;");                container.addChild(errorMessage);                                HtmlBlockContainer resultsContainer = new HtmlBlockContainer();                resultsContainer.setId(key.toString() + "_div");                resultsContainer.setClasses(getAutoCompleteStyleClass());                container.addChild(resultsContainer);                                addFinalScript(container, textField.getId(), resultsContainer.getId(), loadingContainer.getId());                                return container;            }            private void addScripts(HtmlInlineContainer container) {                HttpServletRequest request = getContext().getViewState().getRequest();                                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, String indicatorId) {                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() +                        (isIndicatorShown() ? ", indicator: '" + indicatorId + "'" : "") +                         ", onFailure: function (transport) { showAutoCompleteError('" + textFieldId + "'); }});";                                HtmlScript script = new HtmlScript();                script.setContentType("text/javascript");                script.setScript(scriptText);                                container.addChild(script);            }        };    }