Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

 


<html>

<head>
<title>$i18n.getText("xproduct.admin.label")</title>
<meta name="decorator" content="atl.admin" />

$webResourceManager.requireResource("com.atlassian.plugins.tutorial.tutorial-jira-add-content-to-view-issue-screen:resources")
</head>

< script type="text/javascript">
function validateField() {
alert("test")
}
</script>
<body>
<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="">
<div>
<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()">
Create</button>
</h2><hr>
</div>

<table class="aui">
<thead>
<tr>
<th>$i18n.getText("global.configuration.name")</th>
<th>Issue type(s)</th>
<th>Last update</th>
<th>Updated By</th>
<th>Actions</th>
</tr>
</thead>

<tbody>
#foreach( $globalConfigurationDetails in $globalConfigurationDetailsList )
<tr>
<td>$globalConfigurationDetails.getConfigName()</td>
<td>$globalConfigurationDetails.getIssueType()</td>
<td>$globalConfigurationDetails.getUpdatedDate()</td>
<td>$globalConfigurationDetails.getUpdatedBy()</td>
<td><a target="_blank" href="">Edit</a></td>
</tr>
#end

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

</form>
</body>
</html>

JAVA class snippet

 

@Scanned
public class AdminServlet extends HttpServlet
{
@ComponentImport
private final UserManager userManager;
@ComponentImport
private final LoginUriProvider loginUriProvider;
@ComponentImport
private final TemplateRenderer renderer;

@Inject
public AdminServlet(UserManager userManager, LoginUriProvider loginUriProvider, TemplateRenderer renderer)
{
this.userManager = userManager;
this.loginUriProvider = loginUriProvider;
this.renderer = renderer;
}

@Override
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);
return;
}

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

globalConfigurationDetailsList = DBUtils.fetchGlobalConfigurationDetails();


context.put("globalConfigurationDetailsList", globalConfigurationDetailsList);

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

response.setContentType("text/html;charset=utf-8");

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.

screen_create.PNG

 

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;
}
</style>


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

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

/*AJS.ajaxSetup({
baseUrl: "http://localhost:8090/jira" // The base url of your instance
});

AJS.ajax({
url : '/saveConfigDetails',
type: 'POST',
data : {remarks :x}, // form data
cache : false,
success: function(response){
alert('Success');
}
});*/
//alert(x);
}
</script>


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

</tr>
</thead>

<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>
</tr>
#end-->

#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()">
<div>$issueCheckPointConfig.getCheckPoint()</div></td>
<td headers="bgd3200zb" class="">
<div>
<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>
</select>
</div></td>
<td headers="47ujln567" class="">
<div>
<input type="text" id="remarks" name="remarks" class="text auiTextInput long-field"
value="$issueCheckPointConfig.getRemarks()">
</div>
</td>

</tr>

#end

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

</table>
</form>
</div>

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 

http://localhost:2990/jira/projects/TEST/issues/TEST-2?filter=allopenissues

Like as below,

screen_create.PNG

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="due-date-indicator.name" 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="com.tel.plugins.tutorial.globalConfig.IssueCheckPointsConfiguration"/>
<resource name="view" type="velocity" location="templates/issue-check-point.vm"/>

</web-panel>

 

The Java class is : 

@Scanned
public class IssueCheckPointsConfiguration extends AbstractJiraContextProvider {


@Override
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

http://localhost:2990/jira/projects/TEST/issues/TEST-2?filter=allopenissues

@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 {


@Override
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
TAGS
Community showcase
Published in Agile

Join us LIVE: Atlassian & Experts Talk Research & Insights @ Scale

Hello all! What have you learned from your customers lately? Our live-streamed series continues by exploring CX, UX, and the power of research & insights at scale with Leisa Reichelt, Head of R...

270 views 3 6
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