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 .
Community moderators have prevented the ability to post new answers.
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.
Hi Tousif,
I tried the above , still not able to get the selected value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to set the action of your form to something like
action="${baseurl}/secure/MyAction.jspa"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mizan can you please post your action url and how you handled the redirection to stay on the velocity template
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Probably best to start a new question asking what you actually want to do, this thread was last updated 7 years ago, is DEAD!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andy Brook I have created the question with the following url
What I want to achieve is to pass the value of select box from velocity to Java file
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
new question, perhaps titled 'Not redirecting a user after an action has completed'?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, so you have to create something to 'catch' the POST, see https://developer.atlassian.com/display/JIRADEV/Webwork+plugin+module.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"> " ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.