I want to use the date picker macro in a user macro. The date picker should be a user macro paramter.
Does anyone have any ideas on how I can achieve this?
Hi @Markus ,
You could try this (but just ⚠️ note that I haven't tested this myself; I found it in docs)
Steps to Enable Date Picker as a User Macro Parameter Allow Date Handling in User Macros By default, not all Java methods for date handling are available in user macros due to security restrictions. You need to update your Confluence JVM options to allow the necessary Velocity context keys and date methods. This is done by editing the `setenv.sh` file in your Confluence installation: CATALINA_OPTS="-Dmacro.required.velocity.context.keys=action,page,<additional-keys-if-needed>,userAccessor,content \-Datlassian.velocity.method.allowlist.extra=\"java.util.Calendar#set(int,int,int),java.sql.Timestamp#compareTo(java.util.Date),java.util.Date#compareTo(java.util.Date)\" ${CATALINA_OPTS}" Replace `<additional-keys-if-needed>` with any other keys you require. Restart Confluence After updating the JVM options, restart your Confluence instance to apply the changes. Create the User Macro Go to General Configuration > User Macros. Create a new macro and add a parameter for the date (e.g., `dateParam`). In your macro body, you can use Velocity code to handle and display the date parameter. Here’s a basic example: ## Macro parameter: $paramdateParam (type: date)#set ($calendar = $action.getDateFormatter().getCalendar().getInstance())#set ($userDate = $paramdateParam)Date selected: $action.dateFormatter.formatGivenString("yyyy-MM-dd", $userDate) When you insert this macro on a page, Confluence will provide a date picker UI for the date parameter. Few Notes Always use `$action.dateFormatter` and supported methods for date formatting and comparison. If you encounter issues, double-check your JVM options and ensure the correct methods are allowed.
Steps to Enable Date Picker as a User Macro Parameter
CATALINA_OPTS="-Dmacro.required.velocity.context.keys=action,page,<additional-keys-if-needed>,userAccessor,content \-Datlassian.velocity.method.allowlist.extra=\"java.util.Calendar#set(int,int,int),java.sql.Timestamp#compareTo(java.util.Date),java.util.Date#compareTo(java.util.Date)\" ${CATALINA_OPTS}"
## Macro parameter: $paramdateParam (type: date)#set ($calendar = $action.getDateFormatter().getCalendar().getInstance())#set ($userDate = $paramdateParam)Date selected: $action.dateFormatter.formatGivenString("yyyy-MM-dd", $userDate)
Few Notes
As this probably requires some tweaking (as you can see), maybe a better place for this question would be Developer community (folk there know infrastructure and backend much better than I 😅)
Cheers,Tobi
Hi Tobi,
Thank you for your prompt reply.I believe I lack the necessary knowledge to make such extensive changes to the Confluence configuration :-(I am still hoping to find a solution that I can implement myself using user macro code.
Cheers,Markus
It looks like you're new here. Sign in or register to get started.