Forums

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

passing parameters into Java method call from javascript velocity Templates

Maria Gude
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 17, 2020

Hi, 

I'm working with velocity for the first time and need to update an Active Objects table from a Macro hosted on a page.  I've read a few posts and found that i need to wrap the Java function in a javascript function in order to get the onclick to work properly in a table.  However, I'm having a little trouble passing in the parameter into the java function. 

I have verified that the Java function works alone outside the Javascript method and that the parameter is getting passed into the Javascript method properly, but not the Java method inside.  

 

[Velocity Template]

<script language="JavaScript" type="text/javascript">
function foo(space){
'${services.update(space)}'
}
</script>

...

#foreach($space in $list)
<tr>
<td id=$space.space >$space.space</td>
<td>$space.key</td>
<td><a href="" onclick="foo('$space.space')">Update</a></td>
#end
[Java Class]

@Autowire
private SpaceService spaceService;

public
String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException {
Map context = MacroUtils.defaultVelocityContext();
context.put("list", spaceService.all());
context.put("services", spaceService);
return VelocityUtils.getRenderedTemplate("templates/spaceMacro.vm", context);

Any help is appreciated, thank you!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events