code: private void renderCombinedAutoCompleteScripts()
      {
          final StringBuilder combinedScript = new StringBuilder();
          final EnumSet<AutoCompleteBehavior.Type> types = EnumSet.noneOf(AutoCompleteBehavior.Type.class);
          for (final AutoCompleteHeaderItem curItem : this.autoCompleteItems) {
              for (final AutoCompleteBehavior.Type type : curItem.getTypes()) {
                  if (!types.contains(type)) {
                      types.add(type);
                  }
              }
              combinedScript.append("\n");
              combinedScript.append(curItem.getJavaScript());
              combinedScript.append(";");
          }
  
          if (combinedScript.length() > 0) {
              if (RequestCycle.get().getActiveRequestHandler() instanceof AjaxRequestHandler) {
                  super.render(new OnDomReadyHeaderItem(AutoCompleteHeaderItem.writeJavaScript(
                                  combinedScript.append("\n"), types, false)));
              } else {
                  super.render(AutoCompleteHeaderItem.forScript(combinedScript.append("\n").toString(), types));
              }
          }
      }
docs: Combines all DOM ready and onLoad scripts and renders them as 2 script
  tags.