Macro parameter type / UI representation

Hello there

As of, the parameter type declares the type of the variable and also influences the way the parameter is presented in the macro settings. So far I found two different representations: Boolean and anything else …

Whatever is declared as type, it is probably converted to String except java.lang.Boolean. I tried java.lang.void :wink:

Except it does not exist like “java.lang.whatever” or “java.lang.string”, then the macro vanishes from the available macros …

See Loading...

Is there a list of “supported” types and their UI representation? Is there a way to create a list of values to choose from for a macro parameter. Or a color picker?

1 Like

Any existing Java class is supported. In other words, the parameter type you specify must be an existing Java type. The UI representation depends on whether the type you specify has an associated HTML displayer. If it doesn’t then it falls back on the default HTML displayer, which shows a plain text input to edit the parameter value. Unfortunately this is not documented… but you can see a list of available HTML displayers at . XWiki takes the simple name of the type you specify, makes it lower case and then looks for the corresponding template.

The easiest is to create a Java enum with the allowed values and specify this as the parameter type. The existing enum displayer will display a drop down select with the enum values from your enum type.

Set the type of your parameter to java.awt.Color or any custom “Color” type and then the existing color displayer will show a color picker for your macro parameter.

Hope this helps,


Thank you very much for the insights on this.

I tried color and date, but without success. Maybe this is not yet implemented in 11.10.4? Or I did something wrong …


Also, I didn’t grasp how to attach an enum to the parameter? Do I need to do that from the macro or is it “read” from the default parameter? Probably newbie question …


What type did you use exactly? From the screenshot it seems it did have an effect on the ColorPicker parameter, at least, because it’s field is not a plain text input anymore. The color picker should open when you click on the right (gray) side.

In the same way as you did with the color and date: you set the parameter type to your custom Java enum class. The displayer will then automatically read the values from the specified enum and display them in a drop down select box.

For the color picker, it is “java.awt.Color”
For the date picker, it is “java.util.Date”
For the Enum test, it is “java.lang.Enum”

Where for the Enum I’m not so sure, since this maybe might be like java.lang.Number (superclass) kind of thing …

Tried that already, did not work …

Sorry, lack of (java) development experience and/or imagination :wink:

So where would I declare the class and instantiate the object? Would that be part of the object of the XWiki.WikiMacroParameterClass (like the default value) or ???. Completely lost here …

You need to investigate why. Check at least the JavaScript console to see if there are any JavaScript errors. Look at the Network tab (browser developer tools) to see if the color picker JavaScript / CSS is loaded.

That’s not right. You need to create your custom enum type, i.e. you need to write Java code. See for instance xwiki-platform/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/ at master · xwiki/xwiki-platform · GitHub . So it’s not easy when you have a macro implemented in a wiki page, because you need to package the Java code and add it as a dependency of your macro. And since you need Java for this, you might as well write the macro in Java.

1 Like

There are no JavaScript errors and also no 404 or other errors when loading the page. What would be the library used to show the color picker? JQuery? The only file loaded with “color” in the name is the one from CKEditor:
and for “picker” it is:

What would be the CSS / JS library to look for?

Regarding the ENUM type, I see. Thank you for the sample to start from. Maybe it would be an option to extend the Wiki Macro options to support a predefined list of values? Not sure if this would be a generic requirement and other might deem this useful too …

Anyway, about to upgrade to xWiki 12 right now to be “up to date” …