Jira plugin, using WebItemProvider, seeing 'cannot cast exception' Edited

Jira 7.2.2

I need to generate some menu items dynamically. From what I've read, it seems that the way to do this is to add a web-section in my atlassian-plugin.xml:

<web-section
key="create-document-section"
i18n-name-key="create-document-section.name"
location="opsbar-operations"
weight="100">
<label key="create-document-section.label"/>
</web-section>

And then a web-item-provider stanza:

<web-item-provider key="create-document-menu-item-factory"
name="Create Document Menu Item Factory"
section="create-document-section"
i18n-name-key="create-document-item-factory.name"
class="com.blizzard.web.DynamicLinkFactory" />

And then implement WebItemProvider:

package com.blizzard.web;

import com.atlassian.plugin.web.api.WebItem;
import com.atlassian.plugin.web.api.model.WebFragmentBuilder;
import com.atlassian.plugin.web.api.provider.WebItemProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;



public class
DynamicLinkFactory implements WebItemProvider {

@Override
public Iterable<WebItem> getItems(Map<String, Object> context) {

final List<WebItem> links = new ArrayList<WebItem>();

links.add(new WebFragmentBuilder(10).
id("create_document_item").
label("test").
title("temp").
webItem("create-document-section").
url("/browse/").
build());

return links;
}
}

This compiles and loads into Jira, but when a page is rendered, I get:

...DynamicLinkFactory cannot be cast to 
com.atlassian.plugin.web.api.provider.WebItemProvider'.
Web-items provided by this provider will be ignored.

What am I doing wrong?

 

 

 

1 answer

0 vote
Aleksandr Zuevich Community Champion Sep 26, 2017

Hi Damon,

I've tried your code and got NullPointerException
at com.atlassian.jira.issue.util.IssueOperationsBarUtil$1.apply(IssueOperationsBarUtil.java:196)
at com.atlassian.jira.issue.util.IssueOperationsBarUtil$1.apply(IssueOperationsBarUtil.java:193)

The reason is you don't have styleClass for your webItem so just add empty styleClass string:

links.add(new WebFragmentBuilder(10).
styleClass("").
id("create_document_item").
label("test").
title("temp").
webItem("create-document-section").
url("/browse/").
build());

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

539 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you