Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to render my freemarker template from java?

Deleted user August 4, 2017

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
Marcin Gardias
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 8, 2017

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.

Deleted user August 8, 2017

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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events