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

Extending UserCFType

Kim Wing Fung May 27, 2015

Does anyone know what I may be doing wrong with this class extension:

 

public class CurrentUserCFType extends UserCFType

{

/**

* Return the default user manually defined if any, otherwise return the
* current user.
*/
public Object getDefaultValue(FieldConfig fieldConfig)

{

try
{
ApplicationUser defaultUser = super.getDefaultValue(fieldConfig);
return (defaultUser != null) ? defaultUser : ComponentAccessor.getJiraAuthenticationContext().getUser();
}
catch (FieldValidationException e)
{
System.out.println("2: getDefaultValue: Exception " + e);

log.error("Impossible to set default value for Custom Field: " + fieldConfig.getName(), e);
return null;
}

}

}

 

When the custom field is created there is never a value assigned to it even though there is always a valid user returned by getDefaultValue.

I have tried to trace the call stack and determined that createValue, updateValue, setDefaultValue functions are never called. I'm curious as to the life cycle and operation of a UserCFType as there doesn't appear to be much information regarding this.

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 27, 2015

Well, the first thing you are doing wrong is extending a class that isn't in the API.  UserCFType lives in jira-core, and that means you really shouldn't be touching it.  This is okay if you're building something for your own internal use, but keep in mind that it means you could run into problems during upgrades.  We are allowed to modify and even remove these classes even in bugfix releases.

Generally for a UserCFType, you would do something like this:

<customfield-type key="my-userpicker" name="My User Picker Custom Field Type"
                  i18n-name-key="my.customfieldtype.userpicker.name"
                  class="com.atlassian.jira.issue.customfields.impl.UserCFType">
    <description>My user custom field type.</description>

    <resource type="velocity" name="view" location="templates/plugins/fields/view/view-my-user.vm"/>
    <resource type="velocity" name="edit" location="templates/plugins/fields/edit/edit-my-user.vm"/>
    <resource type="velocity" name="xml" location="templates/plugins/fields/xml/view-my-user-xml.vm"/>
</customfield-type>

 

And customize the viewing and editing of the value doing something different with the velocity templates.  The alternative would be to build the CF type entirely from scratch.  The reason there isn't more information about how to work with UserCFType is that you aren't supposed to; it is not an SPI.

Custom field types, like other plugin modules, lifecycle with the plugin that defines them.

TAGS
AUG Leaders

Atlassian Community Events