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

How do you call a Java method when you submit a form?

Mark Gallardo February 6, 2012

Hi, I'm currently working on modifying the Time Sheet plugin by Andrew Zhdanov to be able to modify the worklog through the plugin.

I'm using JIRA version 4.2.4 and I was wondering how do you call a Java method with the information from the form after you submit it in the .VM file (timesheet-entry.vm)?

Maybe call the Java method in the form action?

Something like:

<form action="JAVA_METHOD()" method="post" >

Here is a snippet of the plugin:

This is the current code:

<td align="center" class="$cellCSS">
      #if ($timeSpent != 0) 
            <form method="post" >
	          <input type="text" size="3" value="$textUtil.getPrettyHours($timeSpent)" />
            </form>
      #end
</td>

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2012

Assuming the class extends JiraWebActionSupport, then the doExecute method will be called. I'm not sure how exactly you'd make it call some other method, but I don't see the need either...?

Actually if you have a url like DoSomething!init.jspa, then your doInit method will be called. So you can post to ActionName!someMethod.jspa, and your doSomeMethod will be called. IIRC.

0 votes
Andriy Zhdanov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

Hi Matt,

Thank you for your insight, at that moment I would not like to duplicate create/update worklog page (like tempo does :) ), but instead pass startDate and returnUrl parameters, and I've trief it, but they are ignored.

Comments appreciated.

Thank you.

0 votes
Andriy Zhdanov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 16, 2012

Hi Mark,

[this is not an answer to the question]

I've recently started to work on this feature, it might be better to collaborate, if you have not done this feature yet. In your screen shot I afraid you missed the point that timesheet summary aggregates timespents, so it may be not completely correct to update an entry, as it may represent several work log records.

Here is my approach, link leads to 'update worklog' page, now it's Jira's standard page, and it wants some better integration.

Available in trunk.

Please drop me an email, if your interested.

Thank you.

MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

If you need to understand the server side more, how a webpage is mapped to a Java class, see the WebWork Sample Plugin

0 votes
srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2012

Either AJAX or JQUERY would help you to resolve the problem. I prefer to go for a javascript validation if the complexity of java method is less.

0 votes
Wojciech Seliga
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2012

I think you mix server-side calls with client-side calls. VM file is processed on the server side and then whatever object you make available in Velocity context (as a variable) is easily callable from velocity file by $variableName.methodName(params)

However after Velocity markup is processed and becomes and HTML file sent to web browser there is no way you can call easily any Java method. Then either you have to use AJAX calls to call some (typically) REST resources on server side (you often need to write your own REST resources offering varous functionalties) or you submit the whole form and then usually a webwork action or a servlet logic is called depending on the URL you submit the form to. By default doExecute() method of selected webwork action is called unless you specify method name (of the same webwork class) using "!" as delimiter (as Jamie points out). From webwork action you can usually call anything which is available for your plugin - any manager (usually injected before), service, util, functionality exposed by other plugins, etc.

For worklog manipulation from a plugin like Timesheet plugin, I would recommend considering using new fresh (as of JIRA 5.0) REST issue resource which allows you to easily POST worklog details against JIRA issue (ideally using an AJAX call from your gadget) - http://docs.atlassian.com/jira/REST/5.0-rc3/#id3226387

I hope it helps.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2012

Assuming the class extends JiraWebActionSupport, then the doExecute method will be called. I'm not sure how exactly you'd make it call some other method, but I don't see th need either...?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events