Get a web-item to link to java code

I feel like this is something obvious, but I can't seem to figure it out. What is the simplest way to get a button to start running code in a Java class? Another related question I have, is where does the relative path of a link element in a web item begin from?

The few open source examples I can find of buttons that do things, rather than link to an absolute URL somewhere, aren't really helping me. I have put a lot of independent research and digging around into this and I am now stumped.

My goal (For now. One step at a time) is to make a button that is exactly the same as the Approve button for a pull request.

Any help with this issue would be amazing!

2 answers

1 accepted

Hi Corin,

Relative links are relative to the root of the product. E.g. if your Stash is at http://localhost/stash, then a URL like /some/path would be http://localhost/stash/some/path.

As far as getting from a web-item button to Java code, there is no "direct" way to do this. You're asking how to take a button clicks on the client, and have it execute some Java code on the server.

This requires either using JS to make an AJAX call to a REST endpoint when the user clicks the button and then alters the current page based on the result your REST endpoint returns, or pointing the button's link to a servlet that serves your custom content in a fresh page.

Cheers,

Adam

Atlassian has great developer docs that will walk through most examples, but probably in some separate places.

* general stash development (make your first plugin)

https://developer.atlassian.com/stash/docs/latest/how-tos/creating-a-stash-plugin.html

* available module types ( your plugin will use 1 or more of these )

https://developer.atlassian.com/stash/docs/latest/reference/plugin-module-types/plugin-modules.html

* matching the UI

https://developer.atlassian.com/display/AUI/Buttons

I have already read through the first two links several times, and yet am still unsure of the answers to my two questions. While I am fully aware that this could be a deficiency on my part, it is not from lack of trying and I was hoping for a more specific answer.

The documentation for web-items doesn't really explain what can be linked to in the link field. Every example I find just links to an absolute URL like "http://www.google.com". The component module seems to be for connecting modules with each other, so I thought it might help me, but the documentation doesn't really explain how to do that, just that it enables such a connection. The section on Creating Plugin Module Instances seemed promising, but it just explains about how parameters to the class are injected, not how to control execution.

I feel like I must be missing some really basic understanding of something, and maybe I am in over my head, but I am not really willing to give up, so any help would be hugely appreciated.

Thanks in advance!

Corin

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
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,769 views 1 5
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