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"

Suggest an answer

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

“No BS” technology solutions with Forty8Fifity

Hey there Community! My name is Vannya Vallejo, the Channel Communication Specialist at Atlassian and I want to help Atlassian users like you learn a little bit more about our Solution Partners and...

797 views 1 11
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