# Macro parameter type / UI representation

**URL:** <https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124>\
**Category:** Help / Discuss\
**Created:** [July 1, 2020, 10:41pm UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124 "2020-07-01T22:41:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beat\_Burgener](https://forum.xwiki.org/user_avatar/forum.xwiki.org/beat_burgener/32/413_2.png) [@Beat\_Burgener](https://forum.xwiki.org/u/Beat_Burgener)\
**Post date:** [July 1, 2020, 10:41pm UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/1 "2020-07-01T22:41:59Z")

</div>

Hello there

As of [https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingMacros/WikiMacroTutorial/#HParameters](https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingMacros/WikiMacroTutorial/#HParameters), 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 😉

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

See [Loading...](https://jira.xwiki.org/browse/XWIKI-17503)

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?

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [July 6, 2020, 9:39am UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/2 "2020-07-06T09:39:04Z")

</div>

> [@Beat\_Burgener](#):
>
> Is there a list of “supported” types

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 [https://github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates/html\_displayer](https://github.com/xwiki/xwiki-platform/tree/master/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates/html_displayer) . XWiki takes the simple name of the type you specify, makes it lower case and then looks for the corresponding template.

> [@Beat\_Burgener](#):
>
> Is there a way to create a list of values to choose from for a macro parameter.

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.

> [@Beat\_Burgener](#):
>
> Or a color picker?

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,  
Marius

---

<div class="post-metadata">

**Author:** ![Beat\_Burgener](https://forum.xwiki.org/user_avatar/forum.xwiki.org/beat_burgener/32/413_2.png) [@Beat\_Burgener](https://forum.xwiki.org/u/Beat_Burgener)\
**Post date:** [July 6, 2020, 10:23pm UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/3 "2020-07-06T22:23:35Z")

</div>

Marius

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 …

![image](https://discourse.xwiki.org/uploads/default/original/2X/b/be616d2f6876ab224d1a52120101516915144708.png)

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 …

Regards!

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [July 8, 2020, 7:08am UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/4 "2020-07-08T07:08:28Z")

</div>

> [@Beat\_Burgener](#):
>
> I tried color and date, but without success.

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.

> [@Beat\_Burgener](#):
>
> Also, I didn’t grasp how to attach an enum to the parameter?

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.

---

<div class="post-metadata">

**Author:** ![Beat\_Burgener](https://forum.xwiki.org/user_avatar/forum.xwiki.org/beat_burgener/32/413_2.png) [@Beat\_Burgener](https://forum.xwiki.org/u/Beat_Burgener)\
**Post date:** [July 8, 2020, 9:23am UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/5 "2020-07-08T09:23:07Z")

</div>

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 …

> [@mflorea](#):
>
> The color picker should open when you click on the right (gray) side.

Tried that already, did not work …

> [@mflorea](#):
>
> you set the parameter type to your custom Java enum class

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

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 …

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [July 8, 2020, 10:54am UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/6 "2020-07-08T10:54:10Z")

</div>

> [@Beat\_Burgener](#):
>
> Tried that already, did not work …

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.

> [@Beat\_Burgener](#):
>
> For the Enum test, it is “java.lang.Enum”

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/IncludeMacroParameters.java at master · xwiki/xwiki-platform · GitHub](https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/IncludeMacroParameters.java#L45) . 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.

---

<div class="post-metadata">

**Author:** ![Beat\_Burgener](https://forum.xwiki.org/user_avatar/forum.xwiki.org/beat_burgener/32/413_2.png) [@Beat\_Burgener](https://forum.xwiki.org/u/Beat_Burgener)\
**Post date:** [August 2, 2020, 10:11pm UTC](https://forum.xwiki.org/t/macro-parameter-type-ui-representation/7124/7 "2020-08-02T22:11:14Z")

</div>

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:  
xwiki/custom/CKEditor\_plugins/colordialog/plugin.js  
xwiki/custom/CKEditor\_plugins/colordialog/lang/en.js  
and for “picker” it is:  
xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.41/plugins/xwiki-resource/resourcePicker.min.css  
xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.41/plugins/xwiki-resource/resourcePicker.bundle.min.js  
xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.41/plugins/xwiki-resource/resourcePicker.min.css

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” …
