Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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 pass a value to a Java class from a .vm file

I have a velocity template page which contains list of entries and a button.On clicking the button i would like to open a page were i can add new entries which in-turn gets populated to the list.

Issue : On clicking the button, i could see the control is going to a Get Method in the Java class,but not able to obtain any values from the vm page . I will be able to open the new page based on the data passed from the velocity template page.

Please suggest what or were have i gone wrong.I had done various trials based on the comments in other quereis.

Below are the code snippet. I tried to call a function but the alert is not coming.But the related Java class is method is called, but the data from form is not obtained

VM File content



<meta name="decorator" content="atl.admin" />


< script type="text/javascript">
function validateField() {
<form id="admin" class="aui">

<div class="aui-page-panel">
<div class="aui-page-panel-inner">

<section class="aui-page-panel-content">

<div id="elements-admin-main">
<div data-reactroot="">
<h2>Global Configuration Checklist

<!-- <input type="submit" value="Create Global Config" class="aui-button aui-button-primary headerCreateBtn">-->
<input type="text" name="createField" value="create">
<button class="aui-button aui-button-primary headerCreateBtn" id="createGlobalConfig" onclick="validateField()">

<table class="aui">
<th>Issue type(s)</th>
<th>Last update</th>
<th>Updated By</th>

#foreach( $globalConfigurationDetails in $globalConfigurationDetailsList )
<td><a target="_blank" href="">Edit</a></td>

</section><!-- .aui-page-panel-content -->
</div><!-- .aui-page-panel-inner -->


JAVA class snippet


public class AdminServlet extends HttpServlet
private final UserManager userManager;
private final LoginUriProvider loginUriProvider;
private final TemplateRenderer renderer;

public AdminServlet(UserManager userManager, LoginUriProvider loginUriProvider, TemplateRenderer renderer)
this.userManager = userManager;
this.loginUriProvider = loginUriProvider;
this.renderer = renderer;

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException

System.out.println("************************************ FROM PRODUCT PLUGIN ####################################");
System.out.println("************************************ Inside the GET Method........... @@@@@@@@@@@@@@@@@@@@@@@");
System.out.println("************************************ ************************************");

System.out.println("*************** ContextPath " +request.getContextPath());
//System.out.println("*************** Get Header " +request.getHeader());
System.out.println("*************** Path Info " +request.getPathInfo());
System.out.println("*************** Request URI " +request.getRequestURI());
System.out.println("*************** Servlet Path " +request.getServletPath());
System.out.println("*************** Request Get Attribute " +request.getAttribute("createField"));

Map<String, Object> context = new HashMap<String, Object> ();

String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
redirectToLogin(request, response);

List<GlobalConfigurationDetails> globalConfigurationDetailsList = new ArrayList<GlobalConfigurationDetails>();

globalConfigurationDetailsList = DBUtils.fetchGlobalConfigurationDetails();

context.put("globalConfigurationDetailsList", globalConfigurationDetailsList);

* Fetch data from DB
// projectDetailsList = DBUtils.fetchProjectName();
System.out.println(" **************** Ïnside the Servelet :: projectDetailsList "+globalConfigurationDetailsList);
context.put("projectName", "Quality Engineering");


renderer.render("admin.vm", context, response.getWriter());






1 answer

1 accepted

Parameters can be accessed through "HttpServletRequest request" object you receive

See request.getParameter("createField") should give you the value "create"

@Alex Medved _ConfiForms_ Thanks a lot for the help..

@Alex Medved _ConfiForms_ I have another requirement, and would like to know how it can be archived.

In the below screen the ticket is now in the status "In-Progress", upon changing the status to DONE , is there any option to check if the user has entered all the Status, Remarks field for all checkpoints under the GLOBAL CONFIGURATION and to show a custom message if a single row data is not filled in .

In the below screen for Checkpoint "Test in Progress" , STATUS and REMARKS are not filled, and if user does the transition of status from In-progress to DONE, the user should be alerted to fill the data.



My VM file is as below,


<style type="text/css">
.init-template-div {
margin-left: 5px;
border: 1px dashed #ccc;
border-radius: 0;
padding: 7px;
transition: background-color 0.01s linear 0.01s;
position: relative;
text-align: center;
.init-template-div > div {
padding: 4px 0;

<script language="javascript" type="text/javascript">

function myFunction() {
//var x = document.getElementById('checkPoint').value;

baseUrl: "http://localhost:8090/jira" // The base url of your instance

url : '/saveConfigDetails',
type: 'POST',
data : {remarks :x}, // form data
cache : false,
success: function(response){

<div id="issue-left" class="module toggle-wrap">
<form class="aui top-label" style="margin-top: 15px;" method="POST">
<table class="aui panelTableHeader">
<th class="element-medium-header">Checkpoints</th>
<th class="element-medium-header">Status</th>
<th class="element-xsmall-header">Remarks</th>


<tbody class="container">

<!--#if ($issueCheckPointConfiguration.isEmpty())
<tr class="elements-row grey-rows-on-edit ">
<td headers="coyxsnmhe" class=""><div>No Saved Records</div></td>
<td headers="bgd3200zb" class=""><div></div></td>
<td headers="47ujln567" class=""><div></div></td>

#set($i = 0)
#foreach( $issueCheckPointConfig in $issueCheckPointConfiguration )
#set($i = $i+1)
<tr class="elements-row grey-rows-on-edit " data-row_id="vfvfs5ks2" id="$i">
<td headers="coyxsnmhe" class="">
<input type="hidden" id="checkPoint" name="checkPoint" value="$issueCheckPointConfig.getCheckPoint()">
<td headers="bgd3200zb" class="">
<select name="status" id="status" >
<option value="Select">Select</option>
<option selected>$issueCheckPointConfig.getStatus()</option>
<option value="YES" >YES</option>
<option value="NO" >NO</option>
<option value="NA" >NA</option>
<td headers="47ujln567" class="">
<input type="text" id="remarks" name="remarks" class="text auiTextInput long-field"



<td headers="47ujln567" class=""><div>
#if($globalConfigurationDetailsList.size() > 0 )
<button class="aui-button aui-button-compact marginRight" aria-disabled="false"


Thanks in Advance.

It feels like web development 101... 

You can have a JavaScript inside your templates and have a client side validation. Or on submit you can have a validation on your servlet side.

I am a bit puzzled about your question - are you asking how to implement that?

My requirement is - During transition how can i validate the entries in the CheckPoints 

Not sure I understand what you mean by "during transition". Is this about issue transition (from one state to another)?

@Alex Medved _ConfiForms_ I was able to resolve the issue, by developing a plugin which can be configured as a validator in the WorkFlow.

Thanks ..

But i have another issue here.

If you look at the above screen shot in my previous comment, i am able to save the Global Configuration. ie, using the URL http://localhost:2990/jira/browse/TEST-2

There are other was by which we can view and update fields in the ticket like accessing the URL 


Like as below,


But from this screen my Java method is not being called.Can you please let me know what might be the issue.

The atlassian-plugin.xml is as below,

<web-panel name="IssueCheckPointsConfiguration" i18n-name-key="" key="due-date-indicator" location="atl.jira.view.issue.left.context" weight="200">
<description key="due-date-indicator.description">Display Global Configuration</description>
<label key="global-configurations.label"></label>

<context-provider class=""/>
<resource name="view" type="velocity" location="templates/issue-check-point.vm"/>



The Java class is : 

public class IssueCheckPointsConfiguration extends AbstractJiraContextProvider {

public Map<String, Object> getContextMap(ApplicationUser applicationUser, JiraHelper jiraHelper) {
Map<String, Object> contextMap = new HashMap<>();
List<IssueCheckPointConfiguration> issueCheckPointConfigurationList = null;

try {

System.out.println("###############$$$$$$$$$$$$ IssueServlet getContextMap() $$$$$$$$$$$$$$#################");
Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
String currentIssueType = currentIssue.getIssueType().getName();
String currentStatusType = currentIssue.getStatus().getName();
boolean saveIssueConfig = false;

contextMap.put("issueCurrentStatus", issueCurrentStatus);



Can you please advise me on where the issue is or how this can be resolved in the case when accessing ticket via and saving the configuration


@Alex Medved _ConfiForms_ 

How to get the linked ticket details in JIRA

I would like to know how to fetch the linked ticket details. Below is the code i am using,

public class IssueCheckPointsConfiguration extends AbstractJiraContextProvider {

public Map<String, Object> getContextMap(ApplicationUser applicationUser, JiraHelper jiraHelper) {

Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
String currentIssueType = currentIssue.getIssueType().getName();


I would like to know if there is any option to get the linked ticket details from the Issue class. 

Is there any way i can get the details from the database, by accessing data from some table.If so please share the table name. I could only identify "jiraissue" table which contains the issue details, but the linked issue details i am not able to get.


Please help.

Suggest an answer

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

Master the art of thinking big, working small: A conversation with John Cutler

Hello all! It has been 20 years since the agile manifesto was introduced, and closer to 40 years since software development began moving away from a waterfall-type approach. While many teams have ...

1,896 views 10 37
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