Can't use contentPropertyManager anymore in user macro since 7.0.3

Hi,

I can’t use contentPropertyManager anymore in user macros since i updated Confluence to 7.0.3.

Why?

I’m accessing contentPropertyManager like this:


#set $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set ($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set ($containerManager=$getInstanceMethod.invoke(null,null))
#set ($containerContext=$containerManager.containerContext)
#set ($contentPropertyManager=$containerContext.getComponent('contentPropertyManager'))

$contentPropertyManager.setStringProperty($content, "myProperty", "Stuff")

what i get is the plain line of code “$contentPropertyManager.setStringProperty($content, “myProperty”, “Stuff”)” as a string… in earlier versions it rendered the contentPropertyManager value i was asking for…

From the Confluence 7.0.3 JavaDocs:

This interface should be considered almost-deprecated - unless you’re retrieving or modifying existing content properties that were added using a ContentPropertyManager, you should use the entity’s ContentProperties instead.

Have you tried that?

Alright, do you know how to use that in a user macro?
You have to do some REST stuff i guess?

I don’t use user macros that much but the docs say that you should use the entitys ContentProperties instead of using the ContentPropertyManager.

So using the provided $content variable you could probably just call ContentEntityObject#getProperties and use ContentProperties#setStringProperty on it. After that you should be able to save your modified properties using ContentEntityObject#replaceContentProperties.

1 Like

Nice! Thank you!

Now I can save and load properties from within a user macro like this:

## @param Status:title=Status|type=string|required=true|desc=Status to display

#set ( $props = $content.getProperties() )
#set ( $newProps = $props.setStringProperty("test", $paramStatus) )
## $content.replaceContentProperties($newProps)

$content.getProperties().getStringProperty("test")

But I don’t understand how to use replaceContentProperties function properly.
Maybe I must create a new ContentProperties object and than pass it to the replaceContentProperties function instead of using the ContentProperties object of that given $content?

Well it works like this too, but normally I should use the replaceContentProperties function…
If I uncomment “## $content.replaceContentProperties($newProps)”, it just prints me the line, like if it’s not doing anything.

Wait - I missed replaceContentProperties being protected. Sorry for that.

Are you saying it works fine with just calling setStringProperty? If yes, then you’re good. :slight_smile:

Ahh alright!

And yes, without that line it’s working fine :slight_smile:

Thanks a lot!!! You saved my day


so the final lines of code are:

#set ( $props = $content.getProperties() )
$props.setStringProperty("name", "value")

And to get it:
$content.getProperties().getStringProperty("name")

1 Like