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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to call java method from velocity?

I wrote custom field plugin. Now i needed call java method from view.vm

I tried use


in java class i have method

public void show() {

but i couldn't call method.

In this method i want chande data in custom field, save to DB and update on page.

Or how do call or how best to implement this method (maybe on jQuery or other)?

7 answers

This is from an issue tab panel, but I think this will be the same on a custom field. In the java class you wish to make available, you would usually have an override to the populateVelocityParams method, something like this:-

protected void populateVelocityParams(Map params) 
	params.put("instance", this);

So in this case, if my class (this) had a method call show that I wanted to call, I would use


Instance of course being the name of the parameter I put in the map

Thanks for reply, but it couldn't call my method

This Worked perfectly fine for me... Thank you Graeme!

Hi guys, I have the same problem, I need to call the method when a button is pressed, not when the velocity is loaded (that's how is working for me right now), the method is executed when the page is loaded, not when the button is pressed, have you figured out a solution for this?

Thank you.

For a method that returns a string (using your example):

This is your method in Java:

public String show() {
		return "sample";

This is how you call it from velocity:


For a method that returns a boolean value:

This is your method in Java:

public boolean isTrueStatement() {
		return true;

This is how you handle it in velocity (without the "is" prefix):

	<h3>it's true</h3>
	<h3>it's false</h3>

A good reference is found here:

thanks, but....

i have a method

public String show() {
    return "sshhooww";

also i add velocity param in java class

velParams.put("cls", this);

i was able call meethod from vm only that


i couldn't call method without velocity param "csl"

Main purpose of my question get knowleges, how call method from button method onClick

<input type="button" name="button" value="value" onClick="$" />

i found how call method, but i face a question: why called method button.onClick in velocity when i refresh page brouser (f5)

What is the class that contains the show() method?

Does it extend the JiraActionSupport class?

We need more details.

Does your Java class extend a Custom Field Type?

Did you read through ?

I think you have to override the getVelocityParameters() method and add your object that contains the method using the velocityParameters.put() method.

If all your show() method does is return a string, then just add the returned value from show() as a variable to the velocity parameters map.

public class MyType extends WhateverCFType {

private String show(){
return "bla bla bla";

	public Map<String, Object> getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem) {
		final Map<String, Object> velocityParameters = super.getVelocityParameters(issue, field, fieldLayoutItem);

		return velocityParameters;


and then from velocity, you just call the someStringVariable simply by doing this:


Make sure that your atlassian-plugin.xml contains the <customfield-type>... entry with the corresponding referenced vm files.

Sorry, i lost access to my previous account. \=

yes, i see faq about create custom field, but i see

Now i use as superclass

extends AbstractSingleFieldType&lt;String&gt;

maybe i should use other superclass?

now i override method

    public Map&lt;String, Object&gt; getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem) {
        velParams = super.getVelocityParameters(issue, field, fieldLayoutItem);

        if (!velParams.containsKey("cls")) {
            velParams.put("line00", "ButonName");
            velParams.put("cls", this);
            velParams.put("v_show", show());
        return velParams;
and in atlassian-plugin.xml present note:
&lt;customfield-type name="Field"
		i18n-name-key="" key="field"
		&lt;description key="field.description"&gt;Custom Field Plugin
		&lt;resource name="view" type="velocity"
			location="/templates/customfields/field/view.vm" /&gt;
		&lt;resource name="edit" type="velocity"
			location="/templates/customfields/field/edit.vm" /&gt;

maybe you can help me...

my button:

&lt;input class="button" type="button" name="button" value="$line00" onclick="$v_show" /&gt;

i set breakpoint on method show.

when i click on button -- method not called, and if i refresh page with field -- method called twice. why?

maybe problem in velocity?

		&lt;input class="input" type="button" name="button" value="$line00" onclick="$v_show" /&gt;

Hi Alex,

I have a similar requirement and seem to be having the same problem, The method gets called twice but not on the button click. Did you figure out a solution for this?


I may be wrong, but I believe your variables should be written this way when you want to add them to a tag attribute :

        &lt;input class="input" type="button" name="button" value="${line00}" onclick="${v_show}" /&gt;


You all were doing it wrong.

Velocity use a different language called VTL.

if you want to call anything from inside apostrophe("....")  you cannot just call like "$" it should be done in the following way


you have to add ! in between $ and

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Agile

On-demand: Fireside chat with Atlassian on scaling agile organizations

Scaling an agile organization and setting it up for success over the long term is a hard thing to do. We hear a common set of questions from customers all the time, questions like: Can agile scal...

4,000 views 2 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you