A question to xwiki.jsx.use

If I use xwiki.jsx.use several times with the same object but with different maps only for the last call a script request is generated within the html code.

An example just for demonstration:

javascript extension object (with parsing and no caching) contains

function do_${request.name} (info) { alert('${request.text}: ' + info) }

a macro like

{{groovy}}
  xwiki.jsx.use(xwiki.context.macro.doc.fullName, [ name:"warning", text:"This is a warning" ] )
  xwiki.jsx.use(xwiki.context.macro.doc.fullName, [ name:"error", text:"This is a error" ] )
  '''
{{html clean="false"}}
  <button onclick="do_warning('This is the LAST warning!!!')">warn</button>
  <button onclick="do_error('Your first error')">error</button>
{{/html}}
  '''
{{/groovy}}

creates 2 buttons, but only for the last one the javascript macro (do_warn) will be generated.

I see that the generated query string has no influence on the check whether the javascript request has already occurred.

Is there a way to force the javascript request (with a different map) a second time?

(The actual graphical javascript application (bpmn.io) is about allowing multiple diagrams in the same document. The easiest way is to enumerate the occurring javascript variables and HTML id’s using velocity in the parser process).

Many thanks for hints and tips

Hi @NorSch,

What would be your code if yow have a map with 10 entries? Would you call xwiki.jsx.use ten times for the same javascript code?

What do you think about a different approach:

  • use only once the xwiki.jsx.use
  • define your map in the JS object
  • use css classes instead of onclick event
  • in JS code, catch the clicks on class names and process the map entries.

Hope it helps!