How to render my freemarker template from java?

Hi,

please I am new to Bamboo development and have some question, if you could hellp me.

I have this xWork:

<xwork key="viewNFTResults" name="View NFT Results">
<package name="nftResults" extends="buildResultView">
<action name="viewNFTResults" class="com.atlassian.sap.nftresults.impl.MyPostJobAction">
<result name="success" type="freemarker">/fragments/view-nft-results-log.ftl</result>
</action>
</package>
</xwork>

<web-item key="NFT:\${planKey}-\${buildNumber}" name="chainNFTResults" section="chainResults.subMenu/chainResults"
weight="80">
<label key="NFT Results"/>
<link linkId="NFT:\${planKey}-\${buildNumber}">/browse/nft_results/viewNFTResults.action?buildKey=${planKey}&amp;buildNumber=${buildNumber}</link>
</web-item>

 

First Question: please any exapmles what I can use instead of  extends="buildResultView", which choises?

Second Question: any examples about the action element? how the result element works?

Third Question: in the MyPostJobAction I implement PostJobAction and I override the excute method, because I need to get some data after every job is finished, here I want to render the view-nft-results-log.ftl file with new context, I do like that:

public class MyPostJobAction extends PlanResultsAction implements PostJobAction {

public void execute(@NotNull StageExecution stageExecution, @NotNull Job job,
@NotNull BuildResultsSummary buildResultsSummary) {

// for example i have here a map that I will fill with my own data
Map<String, Object> objectMap = new HashMap<String, Object>();


objectMap.put("NFTResults", Job);

//from here please how I can provide my ftl file with this map as a new context
and how to render the ftl file also from here after that?
}
thank you very much in advance. 

 

1 answer

1 vote

1. Don't extend PostJobActions, it's not meant for UI at all. It's an action that executes as part of the build process. If you need such thing at all, it should be a separate class.

2. Your action class should be sth like

public class MyAction extends BuildResultsAction {

public String execute() {
BuildResultSummary bs = getBuildResultsSummary();
//do stuff with the result
return SUCCESS; //this is ftl result
}
}

You DON'T render ftl template. Framework does it for you. If you want to use data from the action in the template you expose it by declaring a public method in the action class for instance, if you want to have this in the ftl:

${myData}

 you do the following in the action:

public String getMyData() {
return "blah blah blah";
}

You can use other types than String of course. NFTResults

3. Action return element tells the framework what to do after your action depending on what your action returns. Your execute method returns a string. The string is the matched against defined return elements and matching action is executed. The action can be  for instance rendering an ftl template or redirecting to another action.

Hi Marcin,

Thank you, your answer solved one problem but I still have another one, if you can help me please.

I implemented PostJobAction here becasue I need to perform a functionaltily when the every job is finished and provide the result once agian to the ftl file to show it inside the tab.

That is why I asked about render ftl template from java code.

So, I need to render the ftl template UI after evrey job is finished.

 

Thank you very much in advance. 

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,094 views 0 5
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot