Hendy Irawan created WICKET-5612:
------------------------------------

             Summary: If Wicket JS libs are moved to footer, 
AbstractAutoCompleteBehavior throws "Uncaught ReferenceError: Wicket is not 
defined"
                 Key: WICKET-5612
                 URL: https://issues.apache.org/jira/browse/WICKET-5612
             Project: Wicket
          Issue Type: Improvement
          Components: wicket
    Affects Versions: 6.15.0
         Environment: wicket-bootstrap
            Reporter: Hendy Irawan
         Attachments: wicketrefe.png

I'm moving all JS libs to footer (using wicket-bootstrap also), which works 
very well because Wicket's {{ResourceReference}} has {{getDependencies()}} 
(thanks!! :) ).

However {{AutoCompleteTextField}} is giving JavaScript error, particularly in 
{{AbstractAutoCompleteBehavior}} here:

{code}
        private void renderAutocompleteHead(final IHeaderResponse response)
        {
                
response.render(JavaScriptHeaderItem.forReference(AUTOCOMPLETE_JS));
                final String id = getComponent().getMarkupId();

                String indicatorId = findIndicatorId();
                if (Strings.isEmpty(indicatorId))
                {
                        indicatorId = "null";
                }
                else
                {
                        indicatorId = "'" + indicatorId + "'";
                }

                String initJS = String.format("new 
Wicket.AutoComplete('%s','%s',%s,%s);", id,
                        getCallbackUrl(), constructSettingsJS(), indicatorId);

                final OnDomReadyHeaderItem onDomReady = 
OnDomReadyHeaderItem.forScript(initJS);

                response.render(new WrappedHeaderItem(onDomReady));
        }
{code}

Error:

{code}
Uncaught ReferenceError: Wicket is not defined ?3:6
(anonymous function) ?3:6
{code}

First lines of rendered HTML:

{code}
<!DOCTYPE html>
<html lang="">
<head><link rel="stylesheet" type="text/css" 
href="../wicket/resource/org.apache.wicket.devutils.debugbar.DebugBar/wicket-debugbar-ver-1399102536000.css"
 />
<script type="text/javascript" >
/*<![CDATA[*/
Wicket.Event.add(window, "domready", function(event) { new 
Wicket.AutoComplete('searchTexte','./?3-1.IBehaviorListener.1-navbar-searchForm-searchText',{preselect:
 false,maxHeight: -1,adjustInputWidth: true,useSmartPositioning: 
false,useHideShowCoveredIEFix: true,showListOnEmptyInput: 
false,ignoreBordersWhenPositioning: true,showListOnFocusGain: 
false,throttleDelay: 300,minInputLength: 1,parameterName: 
'q',showCompleteListOnFocusGain: false},null);;});
/*]]>*/
</script>
...
{code}

Suggestion: Change to {{OnLoadHeaderItem}} instead, or a way to make sure the 
script executes after Wicket libraries are loaded.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to