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 votes
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,089 views 13 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot