how to add same macro on single confluence page and handle macro context in execute?

I have created one grate macro, which have two parameters. These parameter I am accessing in execute method of macro class.

Now, when I am adding macro on confluence page it is working as I am expecting, but issue accurs when we are adding same macro two/multiple time on a single page. Here in this case both macro has diffrent parameter values. So both macro need to give diffrent out put as per parameter, but both macro showing the result as per the last added macro parameter.

And one more thing we are calling some Rest methods on page load, which renderd the out put of macro in table.

When i debug the issue come to know the macro context get updated as per the last macro parameter. 

Now here I want's to handle macro parameter both/multiple macro saperatly. Any suggession here...

 

1 answer

This widget could not be displayed.

Suggest you cross check your code. You would have declared some variables as global. This could cause , similar issue. 

I cross checked it but no global veriables are there...
see following method I am using...

@Override
    public String execute(Map<String, String> stringStringMap, String s, ConversionContext conversionContext) throws MacroExecutionException {
        Map<String, Object> macroContext = MacroUtils.defaultVelocityContext();
        long pageId = conversionContext.getEntity().getId();
        String searchScope = stringStringMap.get("searchScope");
        String rootPageTitle = stringStringMap.get("rootPage");
        String spaceId = searchScope;
        boolean isRootPageContext=false;

        if(rootPageTitle !=null) {
            String[] splitValue = rootPageTitle.split(":");
            if(splitValue.length > 1){
                spaceId= splitValue[0];
            }else{
                spaceId = conversionContext.getSpaceKey();
                Page rootPage = pageManager.getPage(spaceId,rootPageTitle);
                pageId = rootPage.getId();
                isRootPageContext=true;
            }
        }

 /*
  ..
  ..
  .. some buisness logic....
 */ 



return VelocityUtils.getRenderedTemplate(resultTemplate, macroContext);
}

Now, what happening when there is only one map all is good. But when I add second macro "macroContext" data update for second macro parameter.. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

601 views 8 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you