Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve the repeated rendering problem in SelectCFType?

Wenjing Liu
Contributor
July 30, 2025

Hi all, I'm developing a jira plugin custom field extends SelectCFType class, and I Override the OptionsManager.getOptions() function, but when I refresh the portal, the options will be rendered repeatedly like below. Could anyone solve this?

And here's my getOptions funciton.

@Override
public Options getOptions(FieldConfig fieldConfig, JiraContextNode jiraContextNode){

try {
List<Option> options = new ArrayList<>();
IQLFacade iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(IQLFacade.class);
String iql = "Key != \"\"";
List<ObjectBean> assets = iqlFacade.findObjects(iql);

log.debug(assets.toString());

for(ObjectBean asset : assets){
String key = asset.getObjectKey();
Integer id = asset.getId();

log.debug(key);
log.debug(id.toString());

options.add(ComponentAccessor.getOptionsManager().createOption(fieldConfig,null,Long.valueOf(id),key));
}
log.debug(options.toString());

return new OptionsImpl(options,fieldConfig,ComponentAccessor.getOptionsManager());

} catch (InsightException e) {
throw new RuntimeException(e);
}
}

Any adivce will be appreciated. Thanks in advance.

Annotation 2025-07-31 102328.png

1 answer

1 accepted

1 vote
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
August 4, 2025

Hi @Wenjing Liu  

The root cause of the problem is the line below:

options.add(ComponentAccessor.getOptionsManager().createOption(fieldConfig, null, Long.valueOf(id), key));

 

This line creates new Option instances every time the field is rendered. Every time this code runs, it adds the new Option to the database.
You must retrieve existing options, not create new ones each time. Options should be defined once (e.g., during configuration or plugin install) and only fetched during rendering.
Something like the below would work for your case
@Override
public Options getOptions(FieldConfig fieldConfig, JiraContextNode jiraContextNode) {
List<Option> existingOptions = ComponentAccessor.getOptionsManager().getOptions(fieldConfig);
return new OptionsImpl(existingOptions, fieldConfig, ComponentAccessor.getOptionsManager());
}
Wenjing Liu
Contributor
August 4, 2025

Oh I see. I solved this problem using your method. Thanks very much!

Tuncay Senturk _Snapbytes_
Community Champion
August 5, 2025

I am glad it worked!

Wenjing Liu
Contributor
August 5, 2025

Thanks very much for your advice! And I'm sorry that I have another question How to develop an Asset Picker? Could you please help me if you have some time? Any advice will be greatly appreciated. Thanks in advance!

Suggest an answer

Log in or Sign up to answer