How Jira plugin custom field value gets processed on the way to .vm templates

半世苍凉 提交于 2019-12-23 20:06:56

问题


Jira server 7.2.1. Custom field plugin.

The question follows this discussion Can't understand, what does method getSingularObjectFromString do? and some info from "Practical jira plugins"

I'm trying to implement a database custom field with basic value-displayValue logic. The field represents an external entity, so I'm storing ID as a value of the field, but displaying NAME. I have two .vm templates: edit and view. I'm trying to choose the right place to convert ID to NAME. I've overridden a method getStringFromSingularObject(Object o) to get the NAME from ID. It works absolutely fine in edit.vm. As a $value variable I get exactly the name, but in view.vm I still get an id as a $value. I've logged the method calls for the method for AbstractSingleFieldType and noticed that

  1. when the page with my field gets rendered: Methods getValueFromIssue, getDatabaseType, getObjectFromDbValue are being called 4 times each (4 cycles in that order). So they are definitely not the place for a query.

  2. when the field is rendered in the edit mode (so the edit.vm is processed) (i.e. create screen or edit screen, : the same methods are called 4 times and then getStringFromSingularObject and getStringValueFromCustomFieldParams are called and they return the name that I want.

  3. when I simply refresh the view issue screen: The method getStringFromSingularObject doesn't get called at all - the source of my problem.

  4. currently in the view issue screen I see ID instead of the name, but when I click on the pencil (edit) I see the right value (the name). Moreover, in that case none of the methods are called. So I guess Jira processes both templates beforehand?

edit.vm

<div class="field-group">
    <label for="cFieldId">
        $customField.name $value
        #if($fieldLayoutItem.required)
            <span class="aui-icon icon-required">Required</span>
        #end
    </label>
    <select class="select cf-select" name="$customField.id" id="$customField.id">
        <option value="">None</option>
        #foreach ($id in $items.keySet())
            #if ($value && $value.equals($items.get($id)))
                <option value="$id" selected="selected">$items.get($id)</option>
            #else
                <option value="$id">$items.get($id)</option>
            #end
        #end
    </select>
</div>

view.vm

<div id="$customField.id-val" class="value type-select" data-fieldtype="select" data-fieldtypecompletekey="com.atlassian.jira.plugin.system.customfieldtypes:select">
    $value
</div>

Once again, edit.vm works fine displaying name as a value and names as options. view.vm works wrong, displaying id. So, the questions are:

  1. why the method, that is kind of responsible for displaying a value doesn't get called on view?
  2. where the $value is really getting set for the view.vm
  3. what other options do I have for my purposes

来源:https://stackoverflow.com/questions/39703254/how-jira-plugin-custom-field-value-gets-processed-on-the-way-to-vm-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!