Calling a Soy template from a Listener

Is it possible to call a soy template from an event Listener? I am working on a blueprint plugin that forces the user to add labels to the page before saving the page. So one of my approaches for that is call the exact dialog box that we get when we try to add labels to the page, but that dialog box should pop up when the use presses the save button on the page. So basically, it should be like this :

public class PageCreatedListener implements DisposableBean {
	
	 protected EventPublisher eventPublisher;
	 private final LabelManager labelManager;
	 private final PageManager pageManager;
	 private final Logger log;

	 
	 public PageCreatedListener(EventPublisher eventPublisher, LabelManager labelManager, PageManager pageManager) {
	        this.eventPublisher = eventPublisher;
	        eventPublisher.register(this);
	        this.labelManager = labelManager;
	        this.pageManager = pageManager;
	        log = LoggerFactory.getLogger(PageCreatedListener.class);
	 }
	 
	 @EventListener
	 public void pageCreateFromTemplateEvent(PageCreateEvent event) {
		/* Call the soy template or the dialog box that
                 * asks the user to add labels from here
                 * Is this possible?
                 */
	 
	 }

        @Override
	public void destroy() throws Exception {
		// TODO Auto-generated method stub
		
	}

}

1 answer

1 accepted

0 votes
Answer accepted
David Simpson Community Champion Feb 03, 2014

No, you've got the wrong end of the stick here.

The listener is really for behind the scenes events and cannot display a thing to the end user.

An example story for an event listener would be:

As a user, I wish Confluence to email a mailing list each time I create a new page.

The PageCreateListener could then send an email in the background for each new page created.

What you're looking for is to modify the behaviour of the Confluence Editor so that a page cannot be saved until a certain number of labels have been added.

As you're using Blueprints, your page will likely already have your Blueprint specific label attached. You need to check for this label on page save and then pop up the labels dialog.

Hope this helps ;)

---

Aside: You could call a soy template from the event listener for example to format an HTML email. You'd need the SoyTemplateRenderer e.g.

<component-import key="soyTemplateRenderer" interface="com.atlassian.soy.renderer.SoyTemplateRenderer"/>

Thanks a lot David!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

292 views 2 12
Read article

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