Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5612

If Wicket JS libs are moved to footer, AbstractAutoCompleteBehavior throws "Uncaught ReferenceError: Wicket is not defined"

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 6.15.0
    • None
    • wicket
    • None
    • wicket-bootstrap

    Description

      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:

      	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));
      	}
      

      Error:

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

      First lines of rendered HTML:

      <!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>
      ...
      

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

      Attachments

        1. wicketrefe.png
          46 kB
          Hendy Irawan

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ceefour Hendy Irawan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: