PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/content/server/jira/platform/webwork.md

https://bitbucket.org/mrzymski/jira-server-docs
Markdown | 219 lines | 180 code | 39 blank | 0 comment | 0 complexity | c01302d9b03463763fa84891af035766 MD5 | raw file
  1. ---
  2. aliases:
  3. - /server/jira/platform/webwork-plugin-module-4227203.html
  4. - /server/jira/platform/webwork-plugin-module-4227203.md
  5. category: reference
  6. confluence_id: 4227203
  7. dac_edit_link: https://developer.atlassian.com/pages/editpage.action?cjm=wozere&pageId=4227203
  8. dac_view_link: https://developer.atlassian.com/pages/viewpage.action?cjm=wozere&pageId=4227203
  9. date: '2017-12-08'
  10. legacy_title: Webwork plugin module
  11. platform: server
  12. product: jira
  13. subcategory: modules
  14. title: Webwork
  15. ---
  16. # Webwork
  17. ## Purpose of this Module Type
  18. A webwork plugin module defines a URL-addressible 'action', allowing JIRA's user-visible functionality to be extended or partially overridden.
  19. ## Configuration
  20. The root element for the WebWork plugin module is `webwork1`. It allows the following attributes and child elements for configuration:
  21. #### Attributes
  22. <table>
  23. <colgroup>
  24. <col style="width: 20%" />
  25. <col style="width: 80%" />
  26. </colgroup>
  27. <thead>
  28. <tr class="header">
  29. <th><p>Name</p></th>
  30. <th><p>Description</p></th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <tr class="odd">
  35. <td><p>class</p></td>
  36. <td><p>The class which implements this plugin module. The class you need to provide depends on the module type. For example, Confluence theme, layout and colour-scheme modules can use classes already provided in Confluence. So you can write a theme-plugin without any Java code. But for macro and listener modules you need to write your own implementing class and include it in your plugin. See the plugin framework guide to <a href="https://developer.atlassian.com/display/DOCS/Creating+Plugin+Module+Instances">creating plugin module instances</a>. The Java class of the module. For this module, it's fine to use <code>Object</code>, as the real brains are in the action classes below.</p>
  37. <p><strong>Required: yes</strong></p>
  38. <p><strong>Default: -</strong></p></td>
  39. </tr>
  40. <tr class="even">
  41. <td><p>key</p></td>
  42. <td><p>The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.</p>
  43. <pre><code>&lt;component-import key=&quot;appProps&quot;
  44. interface=&quot;com.atlassian.sal.api.ApplicationProperties&quot;/&gt;</code></pre>
  45. <p>In the example, <code>appProps</code> is the key for this particular module declaration, for <code>component-import</code>, in this case. I.e. the identifier for this module.</p>
  46. <p><strong>Required: yes</strong></p>
  47. <p><strong>Default: N/A</strong></p></td>
  48. </tr>
  49. <tr class="odd">
  50. <td><p>i18n-name-key</p></td>
  51. <td><p>The localisation key for the human-readable name of the plugin module.</p>
  52. <p><strong>Required: -</strong></p>
  53. <p><strong>Default: -</strong></p></td>
  54. </tr>
  55. <tr class="even">
  56. <td><p>name</p></td>
  57. <td><p>The human-readable name of the plugin module. I.e. the human-readable name of this module. This must be unique across all JIRA add-ons.</p>
  58. <p><strong>Required: -</strong></p>
  59. <p><strong>Default:</strong> The plugin key.</p></td>
  60. </tr>
  61. <tr class="odd">
  62. <td>roles-required</td>
  63. <td><p>The roles-required attribute can be used to only allow access to certain web actions to users which have been granted certain permissions. See <a href="#notes">Notes</a> for more information.</p>
  64. <p><strong>Required: -</strong></p>
  65. <p><strong>Default: -</strong></p></td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. #### Elements
  70. <table>
  71. <colgroup>
  72. <col style="width: 20%" />
  73. <col style="width: 80%" />
  74. </colgroup>
  75. <thead>
  76. <tr class="header">
  77. <th><p>Name</p></th>
  78. <th><p>Description</p></th>
  79. </tr>
  80. </thead>
  81. <tbody>
  82. <tr class="odd">
  83. <td><p>description</p></td>
  84. <td><p>A human-readable description of this WebWork module. May be specified as the value of this element for plain text or with the <code>key</code> attribute to use the value of a key from the i18n system.</p>
  85. <p><strong>Required: -</strong></p></td>
  86. </tr>
  87. <tr class="even">
  88. <td><p>actions</p></td>
  89. <td><p>Specifies WebWork 1 &lt;action&gt;s to define. Must contain at least one &lt;action&gt; element.</p>
  90. <p><strong>Required: yes</strong></p></td>
  91. </tr>
  92. </tbody>
  93. </table>
  94. #### `<action>` Element Attributes
  95. <table>
  96. <colgroup>
  97. <col style="width: 20%" />
  98. <col style="width: 80%" />
  99. </colgroup>
  100. <thead>
  101. <tr class="header">
  102. <th><p>Name</p></th>
  103. <th><p>Description</p></th>
  104. </tr>
  105. </thead>
  106. <tbody>
  107. <tr class="odd">
  108. <td><p>name</p></td>
  109. <td><p>Full name of the class that implements the WebWork action. Actions in JIRA must extend the class <code>com.atlassian.jira.web.action.JiraWebActionSupport</code>. The class <strong>must not</strong> live in a package that JIRA has already reserved; authors should avoid the <code>com.atlassian</code> namespace altogether. The simple name of the class must be unique across all JIRA add-ons. That is, if one add-on has an action class <code>MyEditAction</code> then no other add-on should have an action class <code>MyEditAction</code>. It is recommended that each add-on use a prefix to make their action classes unique.</p>
  110. <p><strong>Required: yes</strong></p></td>
  111. </tr>
  112. <tr class="even">
  113. <td><p>alias</p></td>
  114. <td><p>The path from which this action may be invoked in JIRA. For example, an action with alias <code>MyNewJiraAction</code> would be invoked by the URL <code>http://&lt;my-jira-server&gt;/secure/MyNewJiraAction.jspa</code>.</p>
  115. <p><strong>Required: yes</strong></p></td>
  116. </tr>
  117. <tr class="odd">
  118. <td>roles-required</td>
  119. <td><p>The roles-required attribute can be used to only allow access to certain web actions to users which have been granted certain permissions. See <a href="#notes">Notes</a> for more information.</p>
  120. <p><strong>Required: -</strong></p></td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. #### `<action>` Element Elements
  125. <table>
  126. <colgroup>
  127. <col style="width: 20%" />
  128. <col style="width: 80%" />
  129. </colgroup>
  130. <thead>
  131. <tr class="header">
  132. <th><p>Name</p></th>
  133. <th><p>Description</p></th>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <tr class="odd">
  138. <td><p>view</p></td>
  139. <td><p>Directs where to send the user when the action completes. The <code>name</code> attribute maps to the return value from the overridden action methods (see the WebWork documentation for more details; common values are <code>error</code>, <code>input</code>, and <code>success</code>). The element's value is the path to the renderable view that is sent to the user (see <a href="#notes">Notes</a> for more information).</p>
  140. <p><strong>Required: -</strong></p></td>
  141. </tr>
  142. </tbody>
  143. </table>
  144. ## Example
  145. Here is a sample webwork plugin module:
  146. ``` xml
  147. <webwork1 key="qquserissue" name="Quick Create User Issue" class="java.lang.Object">
  148. <actions>
  149. <action name="com.atlassian.jira.toolkit.action.QuickCreateUserIssueAction" alias="QuickCreateUserIssue">
  150. <view name="createuserissue">/templates/quickcreateuser.vm</view>
  151. </action>
  152. </actions>
  153. </webwork1>
  154. ```
  155. Webwork plugins effectively extend the actions defined in the JIRA `WEB-INF/classes/actions.xml` file. You should look there for examples of what is possible. There is also a <a href="https://bitbucket.org/mdoar/webwork-sample" class="external-link">Webwork Sample plugin</a> that contains many other basic examples.
  156. {{% warning %}}
  157. Use your own package for your action classes!
  158. In the past, plugin authors could rely on a bit of magic: putting their action class in the package `com.atlassian.jira.web.action` was enough to have JIRA find it without specifying the fully qualified class name in `<action name="">`. This was never a good idea, and in a Plugins2 plugin, it will simply not work. Always create a separate package space for your code and stay out of the `com.atlassian` namespace.
  159. {{% /warning %}}
  160. {{% warning %}}
  161. Make sure your template names are unique!
  162. Your views are placed in a common pool, and JIRA simply retrieves the first template that fully matches the path, so if there are two plugins with templates /templates/admin.vm then one of them will be hidden by the other.
  163. {{% /warning %}}
  164. {{% warning %}}
  165. Avoid complex inheritance!
  166. You can override existing actions without worry, but you cannot override an already overridden action. JIRA's WebWork implementation isn't smart enough to resolve polymorphic action hierarchies.
  167. {{% /warning %}}
  168. ## Sample Code
  169. - The JIRA sample plugin shows how to display the project leads in each project Administrator's page
  170. - The <a href="https://bitbucket.org/mdoar/webwork-sample" class="external-link">Webwork Sample plugin</a> contains many simple examples of using Webwork actions
  171. ## Notes
  172. - ### **Renderable Views**
  173. The value of `<view>` should be a <a href="http://velocity.apache.org" class="external-link">Velocity</a> template; in the above example, the template `templates/quickcreateuser.vm` lives in the plugin artifact under that path. JSP views cannot be used from inside plugins; they can be used if they are installed into the JIRA webapp, but this complicates installation, upgrading, and troubleshooting. Use Velocity if you can.
  174. <!-- -->
  175. - ### **Roles Required**
  176. The roles-required attribute can be used to only allow access to certain web actions to users which have been granted certain permissions. The permissions are the short names of com.atlassian.jira.security.Permissions based permissions, and will only work for global based permissions. The three that are most useful are "admin", "sysadmin", and "use".
  177. You can add a roles-required attribute to the parent webwork element, or to a child action element (or both!).
  178. ``` xml
  179. <webwork1 key="reference-actions" name="Reference WebWork Action" class="java.lang.Object" roles-required="use"> <actions> <action name="com.atlassian.jira.dev.reference.plugin.actions.PreparedReferenceAction" alias="PreparedReferenceAction" roles-required="sysadmin"> <view name="success">templates/actions/prepared-reference-action.vm</view> </action> <action name="com.atlassian.jira.dev.reference.plugin.actions.ReferenceAction" alias="ReferenceAction"> <view name="success">templates/actions/reference-action.vm</view> </action> </actions> </webwork1>
  180. ```