Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a Soy template from a Listener

Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2014

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 at David Simpson Apps
Atlassian Partner
February 3, 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"/>

Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2014

Thanks a lot David!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events