wicketwicket-6wicket-1.5wicket-1.6wicketstuff

Add add same javascript file multiple time in single page using apche wicket framework. Is it possible?


I using a loop and each time this function is call but it add only one javascript file. But i want to trigger the functionality of that javascript file each time . Can anyone please help me?

 @Override
    public void renderHead(Component component, IHeaderResponse response) {
      RawJsView rawJsView = RawJsViewPanel.this.model().getObject();

      Map<String, String> requireJsLibraries = rawJsView.getRequireJsLibraries();
      if (!requireJsLibraries.isEmpty()) {
        System.out.println("requireJsLibraries if =========================>");
        response.render(OnDomReadyHeaderItem.forScript(buildRequireJsConfig(requireJsLibraries)));
      }


   }

Solution

  • Wicket contributes just one occurrence of some JS code. See https://github.com/apache/wicket/blob/0c4b88e16a3ec7478fbc8f86991c6b07805ed821/wicket-core/src/main/java/org/apache/wicket/markup/head/OnDomReadyHeaderItem.java#L101

    To overcome it you can do either:

    1. Add something unique to your JS code for each contribution. E.g. pass an unused function parameter with a unique name.

    2. Override #getRenderTokens() for each header item:

      OnDomReadyHeaderItem item = new OnDomReadyHeaderItem(js) {

       @Override
       public Iterable<?> getRenderTokens()
       {
          return Collections.singletonList("javascript-domready-" + somethingUnique);
       }
      

    somethingUnique could be anything that is unique, e.g. a timestamp or UUID