Calling plug-in actions from anywhere?

Hi,

Does it exists a global function similar to the provided by the following method;

com.atlassian.jira.web.action.JiraWebActionSupport.getRedirect(String arg0)

It returns the url for any other action defined in the plugin, but it can only be invoked by an action extending the JiraWebActionSupport class.

I need to call an action from a menu.

Many thanks,

Pablo

1 answer

1 accepted

1 vote

You should be able to call it from anywhere using a link like this:

/secure/YouActionName!viewName.jspa

Doesn't that work? For a menu, use a web-item.

I believe ActionContext.getResponse().sendRedirect(location) will append the correct contextPath. Haven't tried it though, but the Javadocs seem accurate enough

This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

You can also build the url client-side. There should be a

<script type="text/javascript">var contextPath = '';</script>

on every page, with the appropriate value.

Florin is right, but there is an even easier way, your Action classes (should?) probably subclass JiraWebActionSupport, and so, can call: getRedirect("secure/yourapp/Thing!view.jspa"); so long as your action then returns NULL, you will get redirected, with context set accordingly if present.

The problem is that the code is not inside an action, it's in a menu builder. Hence, neither

<script type="text/javascript">var contextPath = '';</script>

can be invoked because is a client based solution nor

ActionContext.getResponse().sendRedirect(location)

because I don't want redirect anything. Simply, pass the menu links to JIRA and let it decide when to redirect (due an user action).

I got at my email another suggestion from from Andy Brook (and not listed in answers !?):

JiraWebActionSupport, and so, can call: getRedirect("secure/yourapp/Thing!view.jspa");

but as the code is not within an action... I tried to create an object by:

JireWebActionSupport jwas = new JiraWebActionSupport();
jwas.getRedirect(...);

but it did not work.

Based on a Florin's suggestion I tried to get the context from the servlet:

ActionContext.getRequest().getContextPath();

that would be perfect. Unfortunately, as it's not invoked from within an action, ActionContext.getRequest() returns null :(

Anyway it opens a new way: is it possible to get the HttpServletRequest from ANYWHERE (not only from an action)?

If it is from a web-item, you don't need to append context path. If not, where is your code? What kind of plugin module is it?

Jobin is right. Web-items do not require a context path. So if those aren't web-items, what are they? What is that menu builder you are using? When is it called and what does it do?

The action is called from a SimpleLinkFactory (implemented by a class) as described in the following link and in the Jobin's book:

https://answers.atlassian.com/questions/69412/adding-dynamic-links-to-user-s-top-navigation-bar

The links are built from within that class. If the contextPath is not added (/jira/secure/MyAction.jspa) then the action is not found. When the context path is present, then it works.

This will get you the full base url.

ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

Use ComponentManager is the older JIRA versions.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
Read article

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