How to create and use gui elements (e.g. button) with XWiki API

I now solved it, thanks to the help of @vmassol.

TL;DR
This is how I did it:

  • build a form with HMTL+Javascript
  • make a HTTP request to a wiki page, URL can be built in JS
  • create a wiki page which parses the URL, retrieves
    document reference & values
  • store the values in the XObject of the referenced document.

Long explanation:
You can simply use a HTML macro to build a HTML form, as you would do it anywhere.
Then you either add a Javascript Extension (JSX) to the page, or you write your code directly in <script>...</script> tags. Then you can invoke JS code from HTML, e.g. when a button is klicked.
This JS code then retrieves the values from the HTML form fields and puts together an URL with parameters.
Then you create a XmlHttpRequest (or whatever) and send the HTTP request. It is going to a wiki page which parses it and retrieves the reference of the target document as well as the field names and values for the XObject you want to set.

Of course, I tried to make things as generic as possible, to make it extendable, but sometimes you still have to handle each field specifically, e.g. in a special HTML input.

The XWiki software doesn’t show very many things on the surface, but when you dig deeper you find out that it’s quite consistent and well thought-through even at details.

Thanks for such a great open source project!

Cheers

3 Likes