Hello,
in a Jira add-on, I like to get the rendered view-HTML of a custom field in an easy way in Java. I have the issue key, the custom field object, and the user name. The solution sould do all the inconvenient stuff like collecting parameters for e. g. CustomFieldRenderer.
The custom field's value isn't sufficient, as that is only a primary key of something another add-on renders.
Best regards, Johannes
By sheer coincidence I think I have found a solution to this problem, so I am leaving it here just in case someone stumbles upon it later.
There is a method in CustomField getViewHtml which apparently does exactly what you want it to do - renders a customfield value into HTML. The problem is it takes some arguments I dont really understand and dont know where and how to obtain. However, I have managed to work around it and it seems to be working fine (tested on some "normal" customfields like cascade select and multiselect).
You basically only need two things - the customfield id (the "customfield_XXXX" code) and the issue from which you want to take the value. The getViewHtml takes three parameters - the issue, a field layout item (I only have a vague idea of what that represents exactly and the documentation isnt exactly complete on this topic) and an action. Now I assume the action is supposed to be something like the Edit/View action on the issue, but how to obtain it in a code goes way beyond me. I have tried to simply create an empty instance of JiraWebActionSupport and by some miracle it actually works.
The following code returns an HTML code for rendering a value of the given customfield from the given issue.
IssueManager issueManager = ComponentAccessor.getIssueManager();
Issue issue = issueManager.getIssueByCurrentKey(issueKey);
FieldLayoutManager fieldLayoutManager = ComponentAccessor.getFieldLayoutManager();
FieldLayout fieldLayout = fieldLayoutManager.getFieldLayout(issue);
FieldLayoutItem fieldLayoutItem = fieldLayout.getFieldLayoutItem(customFieldId);
Action action = new JiraWebActionSupport();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
String rendered = customField.getViewHtml(fieldLayoutItem, action, issue);
Have you had any luck solving this issue? I have ran into this problem several times and havent found any convenient solutions to render custom field values in a nice way, since each type is rendered differently, not even talking about additional customfields added by plugins.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ivana, unfortunetly I didn't find a solution (and I'm no longer on it).
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.