Hi All,
I am trying to retrieve summary of current issue and display it on an issue tab panel.
this is how i am doing it...
public String retSummary(){ JiraHelper jiraHelper = new JiraHelper(); Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); String summary = currentIssue.getSummary(); return summary; } public void populateVelocityParams(Map params){ params.put("issue", this); }
and in the velocity template, if i call $issue.retSummary().
i am getting the bellow error in the issue tab panel
An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ------- org.apache.velocity.exception.MethodInvocationException: Invocation of method 'retSummary' in class com.sts.tabpanel.Velocity threw exception java.lang.NullPointerException at com.sts.tabpanel.tabpanel.test4:perforce/templates/tabpanels/perforce.vm[line 15, column 37] at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:337) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:284) at
and so on...
What mistake have i done? or is it the right way of retrieving current issue details?
if not, please suggest the right way of doing it.
Many thanks,
Sharath TS
Hi All,
Thanks you very much for your valuable inputs.
i finally solved it.
In The main class which extends AbstractIssueTabPanel and implements IssueTabPanel,
In getAction method, we should pass "issue.getSummary()" to the velocity class! like the below line.
return Collections.singletonList(new Velocity(super.descriptor, issue.getSummary()))
then in velocity constructor, initialize variable this.summary = summary
and params.put("summary", summary)
yes, this String summary = currentIssue != null ? currentIssue.getSummary() : ""; code works and ignores NPE. error. but the context here is, lets say i go to a view page of issue TEST-1, which has the issuetabpanel that i have created. In that issue tab panel i need to display details(ex-summary) of TEST-1, likewise details of TEST-2 in its issuetabpanel and so on... the jiraHelper is not fetching details from the current view page of an issue!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure it's correct. Null means that there is no an issue in the context when a method is invoked. Did you try to add a check for a null as I posted in the answer. It can happen that the method is invoked couple times and when it's invoked first teim there is no issue in the context.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could not obtain the current issue details through java but found a workaround through javascript from the below link
https://answers.atlassian.com/questions/117504
Thank you for your inputs.
An answer on how to tackle the NPE or why NPE is showing up in the above java code will be much appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, it is the problem with null. is the code correct? Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); especially .get("issue")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more though. If it's a case with null issue, you can adjust the code:
Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); String summary = currentIssue != null ? currentIssue.getSummary() : ""; return summary;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess that (Issue) jiraHelper.getContextParams().get("issue"); return null and currentIssue.getSummary(); crashes with NullPointerException. Please try to debug the method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
retSummary? Seems you have a typo in there!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. retSummary() is the method given in the code block
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.
Sorry, I didn't notice, my bad! Can you use a different variable name instead of issue? I wonder if issue is in the context already or not. Also, I would check inside the retSummary method to make sure it is successfully retrieving summary and there are no NPEs in that method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
why don't you directly return the issue.
I'd assume that it's not a good idea to return the whole object with 'this'
Try putting the issue or the summary in the map (e.g. params.put(
"issue"
, issue
)
or params.put(
"summary"
, summary
)
)
and then access your data in the template like:
<p>Summary :$summary</p>
public void populateVelocityParams(Map params){ JiraHelper jiraHelper = new JiraHelper(); Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); String summary = currentIssue.getSummary(); params.put("summary", summary); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Florian, Thanks for your reply. I did try doing the way you have mentioned. When it is done this way the whole Activity tab panels disappears! So i am guessing there is some problem in the below lines of code...? JiraHelper jiraHelper = new JiraHelper(); Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue"); String summary = currentIssue.getSummary();
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.
The three lines above seems to be allright. Did you got any error messages in the log/console ?
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.