Hi,
i am new to confluence plugin development struggling with the (not existing) documentation... I have managed so far adding a home page with several variables defined in the wizard. What i would like to achieve now is to add child pages on the base of checkboxes in the wizard. I need to provide several pages but the user should have the ability to choose, which of these pages he needs in the space.
Here is my code so far. If the user checks the "product1" checkbox the product1 page should be added to the space. Otherwise it will not.
atlassian-plugin.xml
... <space-blueprint key="customer-space-blueprint" i18n-name-key="sector.customer-space.name" category="Kunden"> <content-template ref="customer-space-blueprint.home"> <content-template ref="customer-space-blueprint.product1"/> <content-template ref="customer-space-blueprint.product2"/> </content-template> <dialog-wizard key="customer-space-blueprint.wizard"> ... <dialog-page id="wizardProducts" template-key="Sector.SpaceBlueprints.CustomerSpace.wizardProducts" title-key="sector.customer-space.wizard.title" description-header-key="sector.customer-space.wizard.heading" description-content-key="sector.customer-space.wizard.description" last="true" /> </dialog-wizard> </space-blueprint>
wizardProduct.soy
{namespace Sector.SpaceBlueprints.CustomerSpace} /** * Dialog form template * * @param atlToken the XSRF token to send with the form */ {template .wizardProducts} <form action="#" method="post" id="decisions-form" class="common-space-form aui"> <fieldset> <div class="field-group"> <label for="product1">Product1</label> <input id="product1" type="checkbox" class="checkbox" name="contentTemplateKey" value="customer-space-blueprint.product1"> </div> <div class="field-group"> <label for="product2">Product2</label> <input id="product2" type="checkbox" class="checkbox" name="contentTemplateKey" value="customer-space-blueprint.product2"> </div> </fieldset> <input type="hidden" name="atl_token" value="{$atlToken}" /> </form> {/template}
Community moderators have prevented the ability to post new answers.
Hi Gabriel,
I hope this will help you :)
Right now your space should create all childpages you added in your atlassian-plugin.xml no matter which checkbox ist selected.
The solution for my team member an me was to remove all childpages that were not selected when the space is created.
To achive this try these steps.
Create a java file which extends AbstractBlueprintContextProvider and add the unimplemented methods:
public class AddPages extends AbstractBlueprintContextProvider { @Override protected BlueprintContext updateBlueprintContext(BlueprintContext blueprintContext) { Object checkbox = blueprintContext.get("ID"); return blueprintContext; } }
Replace "ID" with the ID you gave your checkbox in the wizardProduct.soy file.
Your input element of your checkboxes must contain an id field :
<input type="checkbox" id="checkbox" />
Add in your <content-template> sections in atlassian-plugin.xml:
<context-provider class="Path to your Java File "/>
Now you have a reference to your checkbox in the Java file . If the checkbox was not selected the reference will be null.
Now we want to know when the space is created. We have to implement an eventlistener to listen for a SpaceCreateEvent: Add the eventlistener in your java class
public class AddPages extends AbstractBlueprintContextProvider { Page page, parent; @EventListener public void handlePages(PageCreateEvent event) { page = event.getPage(); parent = page.getParent(); removePages(); } @Override protected BlueprintContext updateBlueprintContext(BlueprintContext blueprintContext) { Object checkbox = blueprintContext.get("ID"); return blueprintContext; } }
In order to use the eventlistener you have to link it with the atlassian-plugin.xml.
Add:
<listener name="Add Pages" key="addpages" class="Path_to_your_java_file"> <description>Will listen for user creation events.</description> </listener>
Now the eventlistener gets called when you press "Create" in your Wizard.
We need to save the selection states of the checkboxes in the dialog-wizard
Add in your java file
public class AddPages extends AbstractBlueprintContextProvider { @EventListener public void handlePages(PageCreateEvent event) { page = event.getPage(); parent = page.getParent(); removePages(); } @Override protected BlueprintContext updateBlueprintContext(BlueprintContext blueprintContext) { Object checkbox; checkbox = blueprintContext.get("checkbox"); //your ID! CheckboxesBooleans.setExample(checkbox != null); return blueprintContext; } }
We created another java class CheckboxesBooleans to keep it simple.
public class CheckboxesBooleans { private static boolean example=false; public static boolean getExample() { return example; } public static void setExample(boolean example_boolean) { example = example_boolean; } }
Now we know which checkboxes are selected when the handlePages method gets called.
Add the removePages Method to your original java class
private void removePages() { if (page.getDisplayTitle().contains("__")) { //your page title if (!CheckboxesBooleans.getExample()) parent.removeChild(page); } }
This method gets a childpage and checks if the checkbox for the page was not selected. If so the childpage will be removed.
I simplified our code for explanation purposes. You have to adapt it to your project.
I hope i was able to solve your problem.
Greetings
Marco
I'd just like to drop in my own take on the issue, now in 2019 - I recently completed a task exactly the same as @Gabriel Jülke's and managed to get everything up and running. Maybe it can help whoever stumbles across this thread.
For the most part, all of @Marco Vogel's tutorial is still applicable in the current development state of confluence server at the time of writing this article. I only had to add a couple of functions in order to get the Listener working with the current Spring components. Specifically, by adding in the DisbosableBean element and it's relevant destroy() function will allow all of the code to run smoothly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.