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

How to get values from velocity in java class

Mizan
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 20, 2012

Hi All,

I am creating a version tab panel plugin which provides a select list . I want to to get the value which the user selects in my java class . I am stuck here dont know how to achieve this . Can someone please guide me how to do this ?

below is contents of the velocity file.

<div id="primary" class="column full">
    <div class="content">
        <div class="module">
            <div class="mod-content">
            		
			<form name="input" action="." method="post">
			<select name="parent_version">
			<option value="-1">--select Parent--</option>
			#foreach( $version in $versions )
				<option value="$version">$version</option>
			#end										
		      </select>
			<input type="submit" value="Add Parent" />
			</form>
                        
           </div>
        </div>
    </div>
</div>

thanks in advance

suggestions , comments welcomed .

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
tousifs
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 22, 2012

Hi Mizan,

you can try this it will work.you'r using velocity template as your User Interface : here you need to write the selected value

<option value="$version">$version</option>

$req.session.setAttribute("parent_version", $version )
-- This is the name of select list.
once you have set required object value into session object it will available through context. now you have to use this session object in required class file.
 HttpSession session;
session.getAttribute("parent_version") --- it will return the selected parent_version value.


Mizan
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 22, 2012

Hi Tousif,

I tried the above , still not able to get the selected value.

2 votes
Florin Manaila
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 20, 2012

The java class behind the action of your form should have a "public String execute();" method inherited from JiraAction Support. There, you can do something like this to get the values from your form:

ActionContext.getRequest().getParameterMap()

Mizan
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 20, 2012

Plugin XML

<webwork1 key="addparent" name="Add Parent" class="java.lang.Object">
    <actions>
        <action name="com.mizan.AddParentAction" alias="AddParent">
        </action>
    </actions>
	</webwork1>

Java class

public class AddParentAction extends JiraWebActionSupport{

	ActiveObjects ao; 
	
	protected String doExecute() throws Exception {
			
	           String[] vals = request.getParameterValues("parent_version");

	           log.error("name "+ vals[0]);

	       
		return null;
		
		
	}
	}

velocity of version tab panel

<div id="primary" class="column full">
    <div class="content">
        <div class="module">
            <div class="mod-content">
            		
			<form name="input" action="AddParent" method="get">
			<select name="parent_version">
			<option value="-1">--select Parent--</option>
			#foreach( $version in $versions )
				<option value="$version">$version</option>
			#end										
		      </select>
			<input type="submit" value="Add Parent"/>
			</form>
                        
           </div>
        </div>
    </div>
</div>

I am not able to print the selected value in the log . Somthing i am missing ?

Andy Brook [Plugin People]
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 20, 2012

If you look at the JIRA source code you will find actions that always return something, eg SUCCESS. returning null is going to do... nothing. Returning null is sometimes valid, eg when redirecting.

If you havent done so yet, setup socket debugging for your JIRA, understand when your actions are called.

Looking at the action you probably want to call it 'something' then have a doAddParent() method just like execute, then the form would call: action="Something!addParent.jspa", see the pattern?

Mizan
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 20, 2012

i am reffering this . i just need the value which i have selected so that i can add it in an AO table/entity. will i have to write a jsp file also ?

Andy Brook [Plugin People]
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 20, 2012

Look at the form you posdted. locate the select. Change the name of the select, which will map to a method in your action, call it 'parentVersion' then implement setParentVersion(String stuff){} and breakpoint that.

Andy Brook [Plugin People]
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 20, 2012

Right. Assuming you have now setup debugging you wil be able to see when specific methods are called, or not. What you need to do is fix the 'name' of the select, which will map to a method in your action, call it 'parentVersion' then implement setParentVersion(String stuff){} and breakpoint that. You will see the value provided.

The velocity template renders html, you dont need a jsp file for any of this.

Mizan
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 20, 2012

I am sorry but i did not understand what you meant by What you need to do is fix the 'name' of the select, which will map to a method in your action, call it 'parentVersion' then implement setParentVersion(String stuff){} and breakpoint that.

And is this correct in the velocity file ?

<form name="input" action="AddParent" method="get">

Mizan
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 20, 2012

In the logs i dont get anything . I guess the methods in action class which i created are not getting invoked when i click the "Add Parent " button .

Florin Manaila
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 21, 2012

Try to set the action of your form to something like

action="${baseurl}/secure/MyAction.jspa"
Radek Kantor
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 21, 2012

Hi Mizan,

try add private String parent_version; (base on select name in vm template = <select name="parent_version">) in your action class and its setter/getter.

Like Mizan likes this
0 votes
Ashish Biswal March 13, 2019

Hey @Mizan could you please help what changes you made and how you designed the action URL

Ashish Biswal March 13, 2019

@Mizan can you please post your action url and how you handled the redirection to stay on the velocity template 

Andy Brook
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.
March 13, 2019

Probably best to start a new question asking what you actually want to do, this thread was last updated 7 years ago,  is DEAD!

Ashish Biswal March 13, 2019

Hi Andy Brook I have created the question with the following url 

https://community.atlassian.com/t5/Agile-questions/How-to-call-the-java-file-method-and-pass-values-to-it-from-the/qaq-p/1017382#U1031467

What I want to achieve is to pass the value of select box from velocity to Java file 

0 votes
Mizan
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.
March 4, 2012

Hi Guys ,

Thanks for your constant help , Now I am able to get the value of my select list in my Java class . I followed this document and read all your answers again and did some changes in the velocity file , However now i am directed to a blank page , i want to be on the same page after the action is processed. How can this be done ? Thanks :)

Andy Brook [Plugin People]
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.
March 4, 2012

new question, perhaps titled 'Not redirecting a user after an action has completed'?

0 votes
Andy Brook [Plugin People]
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 20, 2012

OK, so you have to create something to 'catch' the POST, see https://developer.atlassian.com/display/JIRADEV/Webwork+plugin+module.

Andy Brook [Plugin People]
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 20, 2012

Use the source luke!, honestly there is nothing more helpful than the JIRA sourcecode, have a look, get proficient in grep :)

I have action references like:

action="${baseurl}/secure/admin/jemh/JEMHConfiguration!update.jspa"

Mizan
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 20, 2012

Hi Andy ,

Thanx for the qiuck response . So in the above velocity file after creating a action i just have to specify it like "

<form name="input" action="myAction" method="post"> " ?

Mizan
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 20, 2012

I am familiar with extending the jira action however not with creating a new action . Il go through the webwork documentation . not getting how to get the value in a java class after i click the "Add Parent" button .

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