Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Including JavaScript defined in a Web Resource into a Configuration Form

Paul Henry February 6, 2013

I want to add a Configuration Form to my Confluence Plugin So i have been following the Tutorial

https://developer.atlassian.com/display/CONFDEV/Creating+a+Cross-Platform+Admin+Configuration+Form

However at step 4 where you start creating the Velocity Template im running into issues that the Javascript Resource file is not being included in the generated page.

I downloaded the completted tutorial source and it has the same problem. When i added

$webResourceManager.requireResource("com.atlassian.plugins.tutorial.xproduct-admin-ui-plugin:resources")
to the Velocity Template nothing is generated in the output, the same occurs using the downloaded tutorial source
code. The Web Resource is defined correctly in the plugin definition teh Javascript file is available available i can download it in my browser if i manually enter its correct URL, so my feeling is that the call to the webResourceManager is not ensuring that the resource is added to the generated output.
Further more, as soon as i add the following
<meta name="decorator" content="atl.admin" />

to the template definition the generated form is now wrapped in the standard confluece look and feel etc but the meta definition for the application-base-url no longer are included. The same if i define the actual javascript page manually using a script tag

eg <script type="text/javascript" src="/confluence/s/170/1.0/1/_/download/resources/com.organisation.myplugin:resources/admin.js" ></script>

the same affects the source code for the tutorial

&lt;head&gt;
    &lt;title&gt;$i18n.getText("xproduct.admin.label")&lt;/title&gt;
    $webResourceManager.requireResource("com.atlassian.plugins.tutorial.xproduct-admin-ui-plugin:resources")
    &lt;meta name="decorator" content="atl.admin" /&gt;
    &lt;meta name="application-base-url" content="$applicationProperties.getBaseUrl()"&gt;
  &lt;/head&gt;

So my Question is What is Wrong in the tutorial. How would i correct the tutorial code so that it works correctly... then i can apply that to my own plugin.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Tomas Jakubis August 5, 2014

The decorator is needed for the webResourceManager to work. Also you do not need to include

&lt;meta name="application-base-url" content="$applicationProperties.getBaseUrl()"&gt;

Decorator itself puts

&lt;meta name="ajs-base-url" content="YOUR-BASE-PATH"&gt;
&lt;meta id="confluence-base-url" name="confluence-base-url" content="YOUR-BASE-PATH"&gt;

and other metas, which you can get with JS as following

AJS.$('meta[name=ajs-base-url]').attr("content")

J August 5, 2014

Thomas, I just found out similiar things and got it working now. I didn't know that the confluence-base-url was created b the decorator. Thx again!

0 votes
J August 5, 2014

Turns out I still had the line

&lt;meta name="application-base-url" content="$applicationProperties.getBaseUrl()"&gt;

in my atlassian-plugin.xml which. After removing it the javascript started to work.

I also had to change the

var baseUrl = AJS.$("meta[name='application-base-url']").attr("content");

to

var baseUrl = AJS.$("meta[name='confluence-base-url']").attr("content");

in admin.js because the URL would resolve to a URL where there REST stuff was not reachable.

0 votes
J August 5, 2014

Hm. More than a year later I seem to have run into the exact same problem. The javascript resource file is not included into the velocity template. Therefore all the ajax calls to save/put the data don't work.

Documentation seems to be outdated at many places here.

0 votes
XXX XXX November 19, 2013

I have the same problem. I am VERY disapointed by confluence support. I won't recommand this to anyone.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events