| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| <head> |
| <!-- Matomo --> |
| <script> |
| var _paq = window._paq = window._paq || []; |
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
| _paq.push(["setDoNotTrack", true]); |
| _paq.push(["disableCookies"]); |
| _paq.push(['trackPageView']); |
| _paq.push(['enableLinkTracking']); |
| (function() { |
| var u="https://analytics.apache.org/"; |
| _paq.push(['setTrackerUrl', u+'matomo.php']); |
| _paq.push(['setSiteId', '79']); |
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| })(); |
| </script> |
| <!-- End Matomo Code --> |
| <title>18 Plugins 3.1.9</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen, print" title="Style" charset="utf-8"/> |
| <link rel="stylesheet" href="../css/pdf.css" type="text/css" media="print" title="PDF" charset="utf-8"/> |
| <script type="text/javascript"> |
| function addJsClass() { |
| var classes = document.body.className.split(" "); |
| classes.push("js"); |
| document.body.className = classes.join(" "); |
| } |
| </script> |
| </head> |
| |
| <body class="body" onload="addJsClass();"> |
| <div id="navigation"> |
| <ul> |
| <li> |
| <div id="nav-summary" onmouseover="toggleNavSummary(false)" onmouseout="toggleNavSummary(true)"> |
| <a href="../guide/index.html" class="button">Table of contents</a> |
| |
| <div id="nav-summary-childs" style="display:none;"> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/introduction.html"><strong>1</strong><span>Introduction</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/gettingStarted.html"><strong>2</strong><span>Getting Started</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/upgrading.html"><strong>3</strong><span>Upgrading from previous versions of Grails</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/conf.html"><strong>4</strong><span>Configuration</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/commandLine.html"><strong>5</strong><span>The Command Line</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/profiles.html"><strong>6</strong><span>Application Profiles</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/GORM.html"><strong>7</strong><span>Object Relational Mapping (GORM)</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/theWebLayer.html"><strong>8</strong><span>The Web Layer</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/traits.html"><strong>9</strong><span>Traits</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/webServices.html"><strong>10</strong><span>Web Services</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/async.html"><strong>11</strong><span>Asynchronous Programming</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/validation.html"><strong>12</strong><span>Validation</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/services.html"><strong>13</strong><span>The Service Layer</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/staticTypeCheckingAndCompilation.html"><strong>14</strong><span>Static Type Checking And Compilation</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/testing.html"><strong>15</strong><span>Testing</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/i18n.html"><strong>16</strong><span>Internationalization</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/security.html"><strong>17</strong><span>Security</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/plugins.html"><strong>18</strong><span>Plugins</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/spring.html"><strong>19</strong><span>Grails and Spring</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/hibernate.html"><strong>20</strong><span>Grails and Hibernate</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/scaffolding.html"><strong>21</strong><span>Scaffolding</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/deployment.html"><strong>22</strong><span>Deployment</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0"><a href="../guide/contributing.html"><strong>23</strong><span>Contributing to Grails</span></a> |
| </div> |
| |
| </div> |
| </div> |
| </li> |
| <li class="separator selected"> |
| <a id="ref-button" onclick="localToggle(); return false;" href="#">Quick Reference</a> |
| </li> |
| </ul> |
| </div> |
| <div id="header"> |
| <div class="images clearfix"> |
| |
| <span id="logo"><a href="http://grails.org" target="_blank"><img alt="Grails Logo" title="The Grails Framework" src="../img/grails.png" border="0"/></a></span> |
| |
| |
| </div> |
| <p>See the light - agile, industrial strength, rapid web application development made easy</p> |
| </div> |
| |
| |
| <table id="colset" border="0" cellpadding="0" cellspacing="0"> |
| <tr> |
| <td id="col1"> |
| <div id="main" class="corner-all"> |
| |
| |
| <div class="toc-item prev-left"><a href="../guide/security.html"><< <strong>17</strong><span>Security</span></a></div> |
| |
| |
| <span id='toggle-col1' class="toggle">(<a href="#" onclick="localToggle(); return false;">Quick Reference</a>)</span> |
| |
| |
| <div class="toc-item next-right"><a href="../guide/spring.html"><strong>19</strong><span>Grails and Spring</span> >></a></div> |
| |
| |
| |
| <div class="project"> |
| <h1>18 Plugins - Reference Documentation</h1> |
| |
| <p><strong>Authors:</strong> Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari</p> |
| |
| <p><strong>Version:</strong> 3.1.9</p> |
| |
| |
| </div> |
| |
| |
| <div id="table-of-content"> |
| <h2>Table of Contents</h2> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#creatingAndInstallingPlugins"><strong>18.1</strong><span>Creating and Installing Plugins</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#repositories"><strong>18.2</strong><span>Plugin Repositories</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#providingBasicArtefacts"><strong>18.3</strong><span>Providing Basic Artefacts</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#evaluatingConventions"><strong>18.4</strong><span>Evaluating Conventions</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#hookingIntoRuntimeConfiguration"><strong>18.5</strong><span>Hooking into Runtime Configuration</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#addingMethodsAtCompileTime"><strong>18.6</strong><span>Adding Methods at Compile Time</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#addingDynamicMethodsAtRuntime"><strong>18.7</strong><span>Adding Dynamic Methods at Runtime</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#participatingInAutoReloadEvents"><strong>18.8</strong><span>Participating in Auto Reload Events</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#understandingPluginLoadOrder"><strong>18.9</strong><span>Understanding Plugin Load Order</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:0px"><a href="#artefactApi"><strong>18.10</strong><span>The Artefact API</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:10px"><a href="#queryingArtefacts"><strong>18.10.1</strong><span>Asking About Available Artefacts</span></a> |
| </div> |
| |
| <div class="toc-item" style="margin-left:10px"><a href="#customArtefacts"><strong>18.10.2</strong><span>Adding Your Own Artefact Types</span></a> |
| </div> |
| |
| </div> |
| |
| |
| |
| <a name="15. Plug-ins"><!-- Legacy link --></a> |
| <h1 id="plugins">18 Plugins</h1> |
| Grails is first and foremost a web application framework, but it is also a platform. By exposing a number of extension points that let you extend anything from the command line interface to the runtime configuration engine, Grails can be customised to suit almost any needs. To hook into this platform, all you need to do is create a plugin.<p class="paragraph"/>Extending the platform may sound complicated, but plugins can range from trivially simple to incredibly powerful. If you know how to build a Grails application, you'll know how to create a plugin for <a href="../guide/single.html#providingBasicArtefacts" class="guide">sharing a data model</a> or some static resources. |
| |
| |
| <a name="15.1 Creating and Installing Plug-ins"><!-- Legacy link --></a> |
| <h2 id="creatingAndInstallingPlugins">18.1 Creating and Installing Plugins</h2> |
| <h4>Creating Plugins</h4><p class="paragraph"/>Creating a Grails plugin is a simple matter of running the command:<p class="paragraph"/><div class="code"><pre>grails create-plugin [PLUGIN NAME]</pre></div><p class="paragraph"/>This will create a plugin project for the name you specify. For example running <code>grails create-plugin example</code> would create a new plugin project called <code>example</code>.<p class="paragraph"/>In Grails 3.0 you should consider whether the plugin you create requires a web environment or whether the plugin can be used with other profiles. If your plugin does not require a web environment then use the "plugin" profile instead of the "web-plugin" profile:<p class="paragraph"/><div class="code"><pre>grails create-plugin [PLUGIN NAME] --profile=plugin</pre></div><p class="paragraph"/>Make sure the plugin name does not contain more than one capital letter in a row, or it won't work. Camel case is fine, though.<p class="paragraph"/>The structure of a Grails plugin is very nearly the same as a Grails application project's except that in the <code>src/main/groovy</code> directory under the plugin package structure you will find a plugin descriptor class (a class that ends in "GrailsPlugin").<p class="paragraph"/>Being a regular Grails project has a number of benefits in that you can immediately test your plugin by running (if the plugin targets the "web" profile):<p class="paragraph"/><div class="code"><pre>grails run-app</pre></div><p class="paragraph"/><blockquote class="note"> |
| Plugin projects don't provide an index.gsp by default since most plugins don't need it. So, if you try to view the plugin running in a browser right after creating it, you will receive a page not found error. You can easily create a <code>grails-app/views/index.gsp</code> for your plugin if you'd like. |
| </blockquote><p class="paragraph"/>The plugin descriptor name ends with the convention <code>GrailsPlugin</code> and is found in the root of the plugin project. For example:<p class="paragraph"/><div class="code"><pre>class ExampleGrailsPlugin { |
| … |
| }</pre></div><p class="paragraph"/>All plugins must have this class under the <code>src/main/groovy</code> directory, otherwise they are not regarded as a plugin. The plugin class defines metadata about the plugin, and optionally various hooks into plugin extension points (covered shortly).<p class="paragraph"/>You can also provide additional information about your plugin using several special properties: |
| <ul class="star"> |
| <li><code>title</code> - short one-sentence description of your plugin</li> |
| <li><code>grailsVersion</code> - The version range of Grails that the plugin supports. eg. "1.2 > *" (indicating 1.2 or higher)</li> |
| <li><code>author</code> - plugin author's name</li> |
| <li><code>authorEmail</code> - plugin author's contact e-mail</li> |
| <li><code>description</code> - full multi-line description of plugin's features</li> |
| <li><code>documentation</code> - URL of the plugin's documentation</li> |
| <li><code>license</code> - License of the plugin</li> |
| <li><code>issueManagement</code> - Issue Tracker of the plugin</li> |
| <li><code>scm</code> - Source code management location of the plugin</li> |
| </ul><p class="paragraph"/>Here is an example from the <a href="http://grails.org/plugin/quartz" target="blank">Quartz Grails plugin</a>:<p class="paragraph"/><div class="code"><pre>class QuartzGrailsPlugin { |
| def grailsVersion = <span class="java-quote">"1.1 > *"</span> |
| def author = <span class="java-quote">"Sergey Nebolsin"</span> |
| def authorEmail = <span class="java-quote">"nebolsin@gmail.com"</span> |
| def title = <span class="java-quote">"Quartz Plugin"</span> |
| def description = '''\ |
| The Quartz plugin allows your Grails application to schedule jobs\ |
| to be executed using a specified interval or cron expression. The\ |
| underlying system uses the Quartz Enterprise Job Scheduler configured\ |
| via Spring, but is made simpler by the coding by convention paradigm.\ |
| ''' |
| def documentation = <span class="java-quote">"http://grails.org/plugin/quartz"</span><p class="paragraph"/> … |
| }</pre></div><p class="paragraph"/><h4>Installing Local Plugins</h4><p class="paragraph"/>To make your plugin available for use in a Grails application run the <code>install</code> command:<p class="paragraph"/><div class="code"><pre>grails install</pre></div><p class="paragraph"/>This will install the plugin into your local Maven cache. Then to use the plugin within an application declare a dependency on the plugin in your <code>build.gradle</code> file:<p class="paragraph"/><div class="code"><pre>compile <span class="java-quote">"org.grails.plugins:quartz:0.1"</span></pre></div><p class="paragraph"/><blockquote class="note"> |
| In Grails 2.x plugins were packaged as ZIP files, however in Grails 3.x plugins are simple JAR files that can be added to the classpath of the IDE. |
| </blockquote><p class="paragraph"/> |
| <h4>Plugins and Multi-Project Builds</h4><p class="paragraph"/>If you wish to setup a plugin as part of a multi project build then follow these steps.<p class="paragraph"/><strong class="bold">Step 1: Create the application and the plugin</strong><p class="paragraph"/>Using the <code>grails</code> command create an application and a plugin:<p class="paragraph"/><div class="code"><pre>$ grails create-app myapp |
| $ grails create-plugin myplugin</pre></div><p class="paragraph"/><strong class="bold">Step 2: Create a settings.gradle file</strong><p class="paragraph"/>In the same directory create a <code>settings.gradle</code> file with the following contents:<p class="paragraph"/><div class="code"><pre>include <span class="java-quote">"myapp"</span>, <span class="java-quote">"myplugin"</span></pre></div><p class="paragraph"/>The directory structure should be as follows:<p class="paragraph"/><div class="code"><pre>PROJECT_DIR |
| - settings.gradle |
| - myapp |
| - build.gradle |
| - myplugin |
| - build.gradle</pre></div><p class="paragraph"/><strong class="bold">Step 3: Declare a project dependency on the plugin</strong><p class="paragraph"/>Within the <code>build.gradle</code> of the application declare a dependency on the plugin within the <code>plugins</code> block:<p class="paragraph"/><div class="code"><pre>grails { |
| plugins { |
| compile project(':myplugin') |
| } |
| }</pre></div><p class="paragraph"/><blockquote class="note"> |
| You can also declare the dependency within the <code>dependencies</code> block, however you will not get subproject reloading if you do this! |
| </blockquote><p class="paragraph"/><strong class="bold">Step 4: Run the application</strong><p class="paragraph"/>Now run the application using the <code>grails run-app</code> command from the root of the application directory, you can use the <code>verbose</code> flag to see the Gradle output:<p class="paragraph"/><div class="code"><pre>$ cd myapp |
| $ grails run-app -verbose</pre></div><p class="paragraph"/>You will notice from the Gradle output that plugins sources are built and placed on the classpath of your application:<p class="paragraph"/><div class="code"><pre>:myplugin:compileAstJava UP-TO-DATE |
| :myplugin:compileAstGroovy UP-TO-DATE |
| :myplugin:processAstResources UP-TO-DATE |
| :myplugin:astClasses UP-TO-DATE |
| :myplugin:compileJava UP-TO-DATE |
| :myplugin:configScript UP-TO-DATE |
| :myplugin:compileGroovy |
| :myplugin:copyAssets UP-TO-DATE |
| :myplugin:copyCommands UP-TO-DATE |
| :myplugin:copyTemplates UP-TO-DATE |
| :myplugin:processResources |
| :myapp:compileJava UP-TO-DATE |
| :myapp:compileGroovy |
| :myapp:processResources UP-TO-DATE |
| :myapp:classes |
| :myapp:findMainClass |
| :myapp:bootRun |
| Grails application running at http://localhost:8080 in environment: development</pre></div><p class="paragraph"/><h4>Notes on excluded Artefacts</h4><p class="paragraph"/>Although the <a href="../ref/Command Line/create-plugin.html" class="commandLine">create-plugin</a> command creates certain files for you so that the plugin can be run as a Grails application, not all of these files are included when packaging a plugin. The following is a list of artefacts created, but not included by <a href="../ref/Command Line/package-plugin.html" class="commandLine">package-plugin</a>: |
| <ul class="star"> |
| <li><code>grails-app/build.gradle</code> (although it is used to generate <code>dependencies.groovy</code>)</li> |
| <li><code>grails-app/conf/application.yml</code> (renamed to plugin.yml)</li> |
| <li><code>grails-app/conf/spring/resources.groovy</code></li> |
| <li><code>grails-app/conf/logback.groovy</code></li> |
| <li>Everything within <code>/src/test/**</code></li> |
| <li>SCM management files within <code>**/.svn/**</code> and <code>**/CVS/**</code></li> |
| </ul><p class="paragraph"/><h4>Customizing the plugin contents</h4><p class="paragraph"/>When developing a plugin you may create test classes and sources that are used during the development and testing of the plugin but should not be exported to the application.<p class="paragraph"/>To exclude test sources you need to modify the <code>pluginExcludes</code> property of the plugin descriptor AND exclude the resources inside your <code>build.gradle</code> file. For example say you have some classes under the <code>com.demo</code> package that are in your plugin source tree but should not be packaged in the application. In your plugin descriptor you should exclude these:<p class="paragraph"/><div class="code"><pre>// resources that should be loaded by the plugin once installed in the application |
| def pluginExcludes = [ |
| '**/com/demo/**' |
| ]</pre></div><p class="paragraph"/>And in your <code>build.gradle</code> you should exclude the compiled classes from the JAR file:<p class="paragraph"/><div class="code"><pre>jar { |
| exclude <span class="java-quote">"com/demo/**/**"</span> |
| }</pre></div><p class="paragraph"/> |
| <h4>Inline Plugins in Grails 3.0</h4><p class="paragraph"/>In Grails 2.x it was possible to specify inline plugins in <code>BuildConfig</code>, in Grails 3.x this functionality has been replaced by Gradle's multi-project build feature.<p class="paragraph"/>To set up a multi project build create an appliation and a plugin in a parent directory:<p class="paragraph"/><div class="code"><pre>$ grails create-app myapp |
| $ grails create-plugin myplugin</pre></div><p class="paragraph"/>Then create a <code>settings.gradle</code> file in the parent directory specifying the location of your application and plugin:<p class="paragraph"/><div class="code"><pre>include 'myapp', 'myplugin'</pre></div><p class="paragraph"/>Finally add a dependency in your application's <code>build.gradle</code> on the plugin:<p class="paragraph"/><div class="code"><pre>compile project(':myplugin')</pre></div><p class="paragraph"/>Using this technique you have achieved the equivalent of inline plugins from Grails 2.x. |
| |
| |
| <a name="15.2 Plugin Repositories"><!-- Legacy link --></a> |
| <h2 id="repositories">18.2 Plugin Repositories</h2> |
| <h4>Distributing Plugins in the Grails Central Plugin Repository</h4><p class="paragraph"/>The preferred way to distribute plugin is to publish to the official Grails Central Plugin Repository. This will make your plugin visible to the <a href="../ref/Command Line/list-plugins.html" class="commandLine">list-plugins</a> command:<p class="paragraph"/><div class="code"><pre>grails list-plugins</pre></div><p class="paragraph"/>which lists all plugins that are in the central repository. Your plugin will also be available to the <a href="../ref/Command Line/plugin-info.html" class="commandLine">plugin-info</a> command:<p class="paragraph"/><div class="code"><pre>grails plugin-info [plugin-name]</pre></div><p class="paragraph"/>which prints extra information about it, such as its description, who wrote, etc.<p class="paragraph"/><blockquote class="note"> |
| If you have created a Grails plugin and want it to be hosted in the central repository, you'll find instructions for getting an account on the <a href="http://grails.org/plugins" target="blank">plugin portal</a> website. |
| </blockquote> |
| |
| |
| <a name="15.4 Providing Basic Artefacts"><!-- Legacy link --></a> |
| <h2 id="providingBasicArtefacts">18.3 Providing Basic Artefacts</h2> |
| <h4>Add Command Line Commands</h4><p class="paragraph"/>A plugin can add new commands to the Grails 3.0 interactive shell in one of two ways. First, using the <a href="../ref/Command Line/create-script.html" class="commandLine">create-script</a> you can create a code generation script which will become available to the application. The <code>create-script</code> command will create the script in the <code>src/main/scripts</code> directory:<p class="paragraph"/><div class="code"><pre>+ src/main/scripts <-- additional scripts here |
| + grails-app |
| + controllers |
| + services |
| + etc.</pre></div><p class="paragraph"/>Code generation scripts can be used to create artefacts within the project tree and automate interactions with Gradle.<p class="paragraph"/>If you want to create a new shell command that interacts with a loaded Grails application instance then you should use the <code>create-command</code> command:<p class="paragraph"/><div class="code"><pre>$ grails create-command MyExampleCommand</pre></div><p class="paragraph"/>This will create a file called <code>grails-app/commands/PACKAGE_PATH/MyExampleCommand.groovy</code> that extends <a href="https://grails.apache.org/docs/3.0.x/api/grails/dev/commands/ApplicationCommand.html" class="api">ApplicationCommand</a>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">import</span> grails.dev.commands.*<p class="paragraph"/>class MyExampleCommand <span class="java-keyword">implements</span> ApplicationCommand {<p class="paragraph"/> <span class="java-object">boolean</span> handle(ExecutionContext ctx) { |
| println <span class="java-quote">"Hello World"</span> |
| <span class="java-keyword">return</span> <span class="java-keyword">true</span> |
| } |
| }</pre></div><p class="paragraph"/>An <code>ApplicationCommand</code> has access to the <code>GrailsApplication</code> instance and is subject to autowiring like any other Spring bean.<p class="paragraph"/>For each <code>ApplicationCommand</code> present Grails will create a shell command and a Gradle task to invoke the <code>ApplicationCommand</code>. In the above example you can invoke the <code>MyExampleCommand</code> class using either:<p class="paragraph"/><div class="code"><pre>$ grails my-example</pre></div><p class="paragraph"/>Or<p class="paragraph"/><div class="code"><pre>$ gradle myExample</pre></div><p class="paragraph"/>The Grails version is all lower case hyphen separated and excludes the "Command" suffix.<p class="paragraph"/>The main difference between code generation scripts and <code>ApplicationCommand</code> instances is that the latter has full access to the Grails application state and hence can be used to perform tasks that interactive with the database, call into GORM etc.<p class="paragraph"/>In Grails 2.x Gant scripts could be used to perform both these tasks, in Grails 3.x code generation and interacting with runtime application state has been cleanly separated.<p class="paragraph"/><h4>Adding a new grails-app artifact (Controller, Tag Library, Service, etc.)</h4><p class="paragraph"/>A plugin can add new artifacts by creating the relevant file within the <code>grails-app</code> tree.<p class="paragraph"/><div class="code"><pre>+ grails-app |
| + controllers <-- additional controllers here |
| + services <-- additional services here |
| + etc. <-- additional XXX here</pre></div><p class="paragraph"/><h4>Providing Views, Templates and View resolution</h4><p class="paragraph"/>When a plugin provides a controller it may also provide default views to be rendered. This is an excellent way to modularize your application through plugins. Grails' view resolution mechanism will first look for the view in the application it is installed into and if that fails will attempt to look for the view within the plugin. This means that you can override views provided by a plugin by creating corresponding GSPs in the application's <code>grails-app/views</code> directory.<p class="paragraph"/>For example, consider a controller called <code>BookController</code> that's provided by an 'amazon' plugin. If the action being executed is <code>list</code>, Grails will first look for a view called <code>grails-app/views/book/list.gsp</code> then if that fails it will look for the same view relative to the plugin.<p class="paragraph"/>However if the view uses templates that are also provided by the plugin then the following syntax may be necessary:<p class="paragraph"/><div class="code"><pre><g:render template=<span class="java-quote">"fooTemplate"</span> plugin=<span class="java-quote">"amazon"</span>/></pre></div><p class="paragraph"/>Note the usage of the <code>plugin</code> attribute, which contains the name of the plugin where the template resides. If this is not specified then Grails will look for the template relative to the application.<p class="paragraph"/><h4>Excluded Artefacts</h4><p class="paragraph"/>By default Grails excludes the following files during the packaging process: |
| <ul class="star"> |
| <li><code>grails-app/conf/logback.groovy</code></li> |
| <li><code>grails-app/conf/application.yml</code> (renamed to <code>plugin.yml</code>)</li> |
| <li><code>grails-app/conf/spring/resources.groovy</code></li> |
| <li>Everything within <code>/src/test/**</code></li> |
| <li>SCM management files within <code>**/.svn/**</code> and <code>**/CVS/**</code></li> |
| </ul><p class="paragraph"/>In addition, the default <code>UrlMappings.groovy</code> file is excluded to avoid naming conflicts, however you are free to add a UrlMappings definition under a different name which <strong class="bold">will</strong> be included. For example a file called <code>grails-app/controllers/BlogUrlMappings.groovy</code> is fine.<p class="paragraph"/>The list of excludes is extensible with the <code>pluginExcludes</code> property:<p class="paragraph"/><div class="code"><pre>// resources that are excluded from plugin packaging |
| def pluginExcludes = [ |
| <span class="java-quote">"grails-app/views/error.gsp"</span> |
| ]</pre></div><p class="paragraph"/>This is useful for example to include demo or test resources in the plugin repository, but not include them in the final distribution. |
| |
| |
| <a name="15.5 Evaluating Conventions"><!-- Legacy link --></a> |
| <h2 id="evaluatingConventions">18.4 Evaluating Conventions</h2> |
| Before looking at providing runtime configuration based on conventions you first need to understand how to evaluate those conventions from a plugin. Every plugin has an implicit <code>application</code> variable which is an instance of the <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsApplication.html" class="api">GrailsApplication</a> interface.<p class="paragraph"/>The <code>GrailsApplication</code> interface provides methods to evaluate the conventions within the project and internally stores references to all artifact classes within your application.<p class="paragraph"/>Artifacts implement the <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsClass.html" class="api">GrailsClass</a> interface, which represents a Grails resource such as a controller or a tag library. For example to get all <code>GrailsClass</code> instances you can do:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">for</span> (grailsClass in application.allClasses) { |
| println grailsClass.name |
| }</pre></div><p class="paragraph"/><code>GrailsApplication</code> has a few "magic" properties to narrow the type of artefact you are interested in. For example to access controllers you can use:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">for</span> (controllerClass in application.controllerClasses) { |
| println controllerClass.name |
| }</pre></div><p class="paragraph"/>The dynamic method conventions are as follows: |
| <ul class="star"> |
| <li><code>*Classes</code> - Retrieves all the classes for a particular artefact name. For example <code>application.controllerClasses</code>.</li> |
| <li><code>get*Class</code> - Retrieves a named class for a particular artefact. For example <code>application.getControllerClass("PersonController")</code></li> |
| <li><code>is*Class</code> - Returns <code>true</code> if the given class is of the given artefact type. For example <code>application.isControllerClass(PersonController)</code></li> |
| </ul><p class="paragraph"/>The <code>GrailsClass</code> interface has a number of useful methods that let you further evaluate and work with the conventions. These include: |
| <ul class="star"> |
| <li><code>getPropertyValue</code> - Gets the initial value of the given property on the class</li> |
| <li><code>hasProperty</code> - Returns <code>true</code> if the class has the specified property</li> |
| <li><code>newInstance</code> - Creates a new instance of this class.</li> |
| <li><code>getName</code> - Returns the logical name of the class in the application without the trailing convention part if applicable</li> |
| <li><code>getShortName</code> - Returns the short name of the class without package prefix</li> |
| <li><code>getFullName</code> - Returns the full name of the class in the application with the trailing convention part and with the package name</li> |
| <li><code>getPropertyName</code> - Returns the name of the class as a property name</li> |
| <li><code>getLogicalPropertyName</code> - Returns the logical property name of the class in the application without the trailing convention part if applicable</li> |
| <li><code>getNaturalName</code> - Returns the name of the property in natural terms (e.g. 'lastName' becomes 'Last Name')</li> |
| <li><code>getPackageName</code> - Returns the package name</li> |
| </ul><p class="paragraph"/>For a full reference refer to the <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsClass.html" class="api">javadoc API</a>. |
| |
| |
| <a name="15.7 Hooking into Runtime Configuration"><!-- Legacy link --></a> |
| <h2 id="hookingIntoRuntimeConfiguration">18.5 Hooking into Runtime Configuration</h2> |
| Grails provides a number of hooks to leverage the different parts of the system and perform runtime configuration by convention.<p class="paragraph"/><h4>Hooking into the Grails Spring configuration</h4><p class="paragraph"/>First, you can hook in Grails runtime configuration overriding the <code>doWithSpring</code> method from the <a href="https://grails.apache.org/docs/3.0.x/api/grails/plugins/Plugin.html" class="api">Plugin</a> class and returning a closure that defines additional beans. For example the following snippet is from one of the core Grails plugins that provides <a href="../guide/single.html#i18n" class="guide">i18n</a> support:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">import</span> org.springframework.web.servlet.i18n.CookieLocaleResolver |
| <span class="java-keyword">import</span> org.springframework.web.servlet.i18n.LocaleChangeInterceptor |
| <span class="java-keyword">import</span> org.springframework.context.support.ReloadableResourceBundleMessageSource |
| <span class="java-keyword">import</span> grails.plugins.*<p class="paragraph"/>class I18nGrailsPlugin <span class="java-keyword">extends</span> Plugin {<p class="paragraph"/> def version = <span class="java-quote">"0.1"</span><p class="paragraph"/> Closure doWithSpring() {{-> |
| messageSource(ReloadableResourceBundleMessageSource) { |
| basename = <span class="java-quote">"WEB-INF/grails-app/i18n/messages"</span> |
| } |
| localeChangeInterceptor(LocaleChangeInterceptor) { |
| paramName = <span class="java-quote">"lang"</span> |
| } |
| localeResolver(CookieLocaleResolver) |
| }} |
| }</pre></div><p class="paragraph"/>This plugin configures the Grails <code>messageSource</code> bean and a couple of other beans to manage Locale resolution and switching. It using the <a href="../guide/single.html#spring" class="guide">Spring Bean Builder</a> syntax to do so.<p class="paragraph"/><h4>Customizing the Servlet Environment</h4><p class="paragraph"/>In previous versions of Grails it was possible to dynamically modify the generated <code>web.xml</code>. In Grails 3.x there is no <code>web.xml</code> file and it is not possible to programmatically modify the <code>web.xml</code> file anymore.<p class="paragraph"/>However, it is possible to perform the most commons tasks of modifying the Servlet environment in Grails 3.x.<p class="paragraph"/><h4>Adding New Servlets</h4><p class="paragraph"/>If you want to add a new Servlet instance the simplest way is simply to define a new Spring bean in the <code>doWithSpring</code> method:<p class="paragraph"/><div class="code"><pre>Closure doWithSpring() {{-> |
| myServlet(MyServlet) |
| }}</pre></div><p class="paragraph"/>If you need to customize the servlet you can use Spring Boot's <a href="http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/embedded/ServletRegistrationBean.html" class="api">ServletRegistrationBean</a>:<p class="paragraph"/><div class="code"><pre>Closure doWithSpring() {{-> |
| myServlet(ServletRegistrationBean, <span class="java-keyword">new</span> MyServlet(), <span class="java-quote">"/myServlet/*"</span>) { |
| loadOnStartup = 2 |
| } |
| }}</pre></div><p class="paragraph"/><h4>Adding New Servlet Filters</h4><p class="paragraph"/>Just like Servlets, the simplest way to configure a new filter is to simply define a Spring bean:<p class="paragraph"/><div class="code"><pre>Closure doWithSpring() {{-> |
| myFilter(MyFilter) |
| }}</pre></div><p class="paragraph"/>However, if you want to control the order of filter registrations you will need to use Spring Boot's <a href="http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/embedded/FilterRegistrationBean.html" class="api">FilterRegistrationBean</a>:<p class="paragraph"/><div class="code"><pre>myFilter(FilterRegistrationBean) { |
| filter = bean(MyFilter) |
| urlPatterns = ['/*'] |
| order = Ordered.HIGHEST_PRECEDENCE |
| }</pre></div><p class="paragraph"/><blockquote class="note"> |
| Grails' internal registered filters (<code>GrailsWebRequestFilter</code>, <code>HiddenHttpMethodFilter</code> etc.) are defined by incrementing <code>HIGHEST_PRECEDENCE</code> by 10 thus allowing several filters to be inserted before or between Grails' filters. |
| </blockquote><p class="paragraph"/><h4>Doing Post Initialisation Configuration</h4><p class="paragraph"/>Sometimes it is useful to be able do some runtime configuration after the Spring <a href="http://docs.spring.io/spring/docs/4.0.x/javadoc-api/org/springframework/context/ApplicationContext.html" class="api">ApplicationContext</a> has been built. In this case you can define a <code>doWithApplicationContext</code> closure property.<p class="paragraph"/><div class="code"><pre>class SimplePlugin <span class="java-keyword">extends</span> Plugin{<p class="paragraph"/> def name = <span class="java-quote">"simple"</span> |
| def version = <span class="java-quote">"1.1"</span><p class="paragraph"/> @Override |
| void doWithApplicationContext() { |
| def sessionFactory = applicationContext.sessionFactory |
| // <span class="java-keyword">do</span> something here with session factory |
| } |
| }</pre></div> |
| |
| |
| |
| <h2 id="addingMethodsAtCompileTime">18.6 Adding Methods at Compile Time</h2> |
| Grails 3.0 makes it easy to add new traits to existing artefact types from a plugin. For example say you wanted to add methods for manipulating dates to controllers. This can be done by defining a trait in <code>src/main/groovy</code>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">package</span> myplugin<p class="paragraph"/>@Enhances(<span class="java-quote">"Controller"</span>) |
| trait DateTrait { |
| Date currentDate() { |
| <span class="java-keyword">return</span> <span class="java-keyword">new</span> Date() |
| } |
| }</pre></div><p class="paragraph"/>The <code>@Enhances</code> annotation defines the types of artefacts that the trait should be applied to.<p class="paragraph"/>As an alternative to using the <code>@Enhances</code> annotation above, you can implement a <a href="https://grails.apache.org/docs/3.0.x/api/grails/compiler/traits/TraitInjector.html" class="api">TraitInjector</a> to tell Grails which artefacts you want to inject the trait into at compile time:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">package</span> myplugin<p class="paragraph"/>@CompileStatic |
| class ControllerTraitInjector <span class="java-keyword">implements</span> TraitInjector {<p class="paragraph"/> @Override |
| <span class="java-object">Class</span> getTrait() { |
| DateTrait |
| }<p class="paragraph"/> @Override |
| <span class="java-object">String</span>[] getArtefactTypes() { |
| ['Controller'] as <span class="java-object">String</span>[] |
| } |
| }</pre></div><p class="paragraph"/>The above <code>TraitInjector</code> will add the <code>DateTrait</code> to all controllers. The <code>getArtefactTypes</code> method defines the types of artefacts that the trait should be applied to. |
| |
| |
| <a name="15.8 Adding Dynamic Methods at Runtime"><!-- Legacy link --></a> |
| <h2 id="addingDynamicMethodsAtRuntime">18.7 Adding Dynamic Methods at Runtime</h2> |
| <h4>The Basics</h4><p class="paragraph"/>Grails plugins let you register dynamic methods with any Grails-managed or other class at runtime. This work is done in a <code>doWithDynamicMethods</code> method.<p class="paragraph"/><blockquote class="note"> |
| Note that Grails 3.x features newer features such as traits that are usable from code compiled with <code>CompileStatic</code>. It is recommended that dynamic behavior is only added for cases that are not possible with traits. |
| </blockquote><p class="paragraph"/><div class="code"><pre>class ExamplePlugin <span class="java-keyword">extends</span> Plugin { |
| void doWithDynamicMethods() { |
| <span class="java-keyword">for</span> (controllerClass in grailsApplication.controllerClasses) { |
| controllerClass.metaClass.myNewMethod = {-> println <span class="java-quote">"hello world"</span> } |
| } |
| } |
| }</pre></div><p class="paragraph"/>In this case we use the implicit application object to get a reference to all of the controller classes' MetaClass instances and add a new method called <code>myNewMethod</code> to each controller. If you know beforehand the class you wish the add a method to you can simply reference its <code>metaClass</code> property.<p class="paragraph"/>For example we can add a new method <code>swapCase</code> to <code>java.lang.String</code>:<p class="paragraph"/><div class="code"><pre>class ExamplePlugin <span class="java-keyword">extends</span> Plugin {<p class="paragraph"/> @Override |
| void doWithDynamicMethods() { |
| <span class="java-object">String</span>.metaClass.swapCase = {-> |
| def sb = <span class="java-keyword">new</span> StringBuilder() |
| delegate.each { |
| sb << (<span class="java-object">Character</span>.isUpperCase(it as <span class="java-object">char</span>) ? |
| <span class="java-object">Character</span>.toLowerCase(it as <span class="java-object">char</span>) : |
| <span class="java-object">Character</span>.toUpperCase(it as <span class="java-object">char</span>)) |
| } |
| sb.toString() |
| }<p class="paragraph"/> assert <span class="java-quote">"UpAndDown"</span> == <span class="java-quote">"uPaNDdOWN"</span>.swapCase() |
| } |
| }</pre></div><p class="paragraph"/><h4>Interacting with the ApplicationContext</h4><p class="paragraph"/>The <code>doWithDynamicMethods</code> closure gets passed the Spring <code>ApplicationContext</code> instance. This is useful as it lets you interact with objects within it. For example if you were implementing a method to interact with Hibernate you could use the <code>SessionFactory</code> instance in combination with a <code>HibernateTemplate</code>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">import</span> org.springframework.orm.hibernate3.HibernateTemplate<p class="paragraph"/>class ExampleHibernatePlugin <span class="java-keyword">extends</span> Plugin{<p class="paragraph"/> void doWithDynamicMethods() {<p class="paragraph"/> <span class="java-keyword">for</span> (domainClass in grailsApplication.domainClasses) {<p class="paragraph"/> domainClass.metaClass.<span class="java-keyword">static</span>.load = { <span class="java-object">Long</span> id-> |
| def sf = applicationContext.sessionFactory |
| def template = <span class="java-keyword">new</span> HibernateTemplate(sf) |
| template.load(delegate, id) |
| } |
| } |
| } |
| }</pre></div><p class="paragraph"/>Also because of the autowiring and dependency injection capability of the Spring container you can implement more powerful dynamic constructors that use the application context to wire dependencies into your object at runtime:<p class="paragraph"/><div class="code"><pre>class MyConstructorPlugin {<p class="paragraph"/> void doWithDynamicMethods() |
| <span class="java-keyword">for</span> (domainClass in grailsApplication.domainClasses) { |
| domainClass.metaClass.constructor = {-> |
| <span class="java-keyword">return</span> applicationContext.getBean(domainClass.name) |
| } |
| } |
| } |
| }</pre></div><p class="paragraph"/>Here we actually replace the default constructor with one that looks up prototyped Spring beans instead! |
| |
| |
| <a name="15.9 Participating in Auto Reload Events"><!-- Legacy link --></a> |
| <h2 id="participatingInAutoReloadEvents">18.8 Participating in Auto Reload Events</h2> |
| <h4>Monitoring Resources for Changes</h4><p class="paragraph"/>Often it is valuable to monitor resources for changes and perform some action when they occur. This is how Grails implements advanced reloading of application state at runtime. For example, consider this simplified snippet from the Grails <code>ServicesPlugin</code>:<p class="paragraph"/><div class="code"><pre>class ServicesGrailsPlugin <span class="java-keyword">extends</span> Plugin { |
| … |
| def watchedResources = <span class="java-quote">"file:./grails-app/services/*Service.groovy"</span><p class="paragraph"/> … |
| void onChange( Map<<span class="java-object">String</span>, <span class="java-object">Object</span>> event) { |
| <span class="java-keyword">if</span> (event.source) { |
| def serviceClass = grailsApplication.addServiceClass(event.source) |
| def serviceName = <span class="java-quote">"${serviceClass.propertyName}"</span> |
| beans { |
| <span class="java-quote">"$serviceName"</span>(serviceClass.getClazz()) { bean -> |
| bean.autowire = <span class="java-keyword">true</span> |
| } |
| } |
| } |
| } |
| }</pre></div><p class="paragraph"/>First it defines <code>watchedResources</code> as either a String or a List of strings that contain either the references or patterns of the resources to watch. If the watched resources specify a Groovy file, when it is changed it will automatically be reloaded and passed into the <code>onChange</code> closure in the <code>event</code> object.<p class="paragraph"/>The <code>event</code> object defines a number of useful properties: |
| <ul class="star"> |
| <li><code>event.source</code> - The source of the event, either the reloaded <code>Class</code> or a Spring <code>Resource</code></li> |
| <li><code>event.ctx</code> - The Spring <code>ApplicationContext</code> instance</li> |
| <li><code>event.plugin</code> - The plugin object that manages the resource (usually <code>this</code>)</li> |
| <li><code>event.application</code> - The <code>GrailsApplication</code> instance</li> |
| <li><code>event.manager</code> - The <code>GrailsPluginManager</code> instance</li> |
| </ul><p class="paragraph"/>These objects are available to help you apply the appropriate changes based on what changed. In the "Services" example above, a new service bean is re-registered with the <code>ApplicationContext</code> when one of the service classes changes.<p class="paragraph"/><h4>Influencing Other Plugins</h4><p class="paragraph"/>In addition to reacting to changes, sometimes a plugin needs to "influence" another.<p class="paragraph"/>Take for example the Services and Controllers plugins. When a service is reloaded, unless you reload the controllers too, problems will occur when you try to auto-wire the reloaded service into an older controller Class.<p class="paragraph"/>To get around this, you can specify which plugins another plugin "influences". This means that when one plugin detects a change, it will reload itself and then reload its influenced plugins. For example consider this snippet from the <code>ServicesGrailsPlugin</code>:<p class="paragraph"/><div class="code"><pre>def influences = ['controllers']</pre></div><p class="paragraph"/><h4>Observing other plugins</h4><p class="paragraph"/>If there is a particular plugin that you would like to observe for changes but not necessary watch the resources that it monitors you can use the "observe" property:<p class="paragraph"/><div class="code"><pre>def observe = [<span class="java-quote">"controllers"</span>]</pre></div><p class="paragraph"/>In this case when a controller is changed you will also receive the event chained from the controllers plugin.<p class="paragraph"/>It is also possible for a plugin to observe all loaded plugins by using a wildcard:<p class="paragraph"/><div class="code"><pre>def observe = [<span class="java-quote">"*"</span>]</pre></div><p class="paragraph"/>The Logging plugin does exactly this so that it can add the <code>log</code> property back to <em class="italic">any</em> artefact that changes while the application is running. |
| |
| |
| <a name="15.10 Understanding Plug-in Load Order"><!-- Legacy link --></a> |
| <h2 id="understandingPluginLoadOrder">18.9 Understanding Plugin Load Order</h2> |
| <h4>Controlling Plugin Dependencies</h4><p class="paragraph"/>Plugins often depend on the presence of other plugins and can adapt depending on the presence of others. This is implemented with two properties. The first is called <code>dependsOn</code>. For example, take a look at this snippet from the Hibernate plugin:<p class="paragraph"/><div class="code"><pre>class HibernateGrailsPlugin {<p class="paragraph"/> def version = <span class="java-quote">"1.0"</span><p class="paragraph"/> def dependsOn = [dataSource: <span class="java-quote">"1.0"</span>, |
| domainClass: <span class="java-quote">"1.0"</span>, |
| i18n: <span class="java-quote">"1.0"</span>, |
| core: <span class="java-quote">"1.0"</span>] |
| }</pre></div><p class="paragraph"/>The Hibernate plugin is dependent on the presence of four plugins: the <code>dataSource</code>, <code>domainClass</code>, <code>i18n</code> and <code>core</code> plugins.<p class="paragraph"/>The dependencies will be loaded before the Hibernate plugin and if all dependencies do not load, then the plugin will not load.<p class="paragraph"/>The <code>dependsOn</code> property also supports a mini expression language for specifying version ranges. A few examples of the syntax can be seen below:<p class="paragraph"/><div class="code"><pre>def dependsOn = [foo: <span class="java-quote">"* > 1.0"</span>] |
| def dependsOn = [foo: <span class="java-quote">"1.0 > 1.1"</span>] |
| def dependsOn = [foo: <span class="java-quote">"1.0 > *"</span>]</pre></div><p class="paragraph"/>When the wildcard * character is used it denotes "any" version. The expression syntax also excludes any suffixes such as -BETA, -ALPHA etc. so for example the expression "1.0 > 1.1" would match any of the following versions: |
| <ul class="star"> |
| <li>1.1</li> |
| <li>1.0</li> |
| <li>1.0.1</li> |
| <li>1.0.3-SNAPSHOT</li> |
| <li>1.1-BETA2</li> |
| </ul><p class="paragraph"/><h4>Controlling Load Order</h4><p class="paragraph"/>Using <code>dependsOn</code> establishes a "hard" dependency in that if the dependency is not resolved, the plugin will give up and won't load. It is possible though to have a weaker dependency using the <code>loadAfter</code> and <code>loadBefore</code> properties:<p class="paragraph"/><div class="code"><pre>def loadAfter = ['controllers']</pre></div><p class="paragraph"/>Here the plugin will be loaded after the <code>controllers</code> plugin if it exists, otherwise it will just be loaded. The plugin can then adapt to the presence of the other plugin, for example the Hibernate plugin has this code in its <code>doWithSpring</code> closure:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">if</span> (manager?.hasGrailsPlugin(<span class="java-quote">"controllers"</span>)) { |
| openSessionInViewInterceptor(OpenSessionInViewInterceptor) { |
| flushMode = HibernateAccessor.FLUSH_MANUAL |
| sessionFactory = sessionFactory |
| } |
| grailsUrlHandlerMapping.interceptors << openSessionInViewInterceptor |
| }</pre></div><p class="paragraph"/>Here the Hibernate plugin will only register an <code>OpenSessionInViewInterceptor</code> if the <code>controllers</code> plugin has been loaded. The <code>manager</code> variable is an instance of the <a href="https://grails.apache.org/docs/3.0.x/api/grails/plugins/GrailsPluginManager.html" class="api">GrailsPluginManager</a> interface and it provides methods to interact with other plugins.<p class="paragraph"/>You can also use the <code>loadBefore</code> property to specify one or more plugins that your plugin should load before:<p class="paragraph"/><div class="code"><pre>def loadBefore = ['rabbitmq']</pre></div><p class="paragraph"/><h4>Scopes and Environments</h4><p class="paragraph"/>It's not only plugin load order that you can control. You can also specify which environments your plugin should be loaded in and which scopes (stages of a build). Simply declare one or both of these properties in your plugin descriptor:<p class="paragraph"/><div class="code"><pre>def environments = ['development', 'test', 'myCustomEnv'] |
| def scopes = [excludes:'war']</pre></div><p class="paragraph"/>In this example, the plugin will only load in the 'development' and 'test' environments. Nor will it be packaged into the WAR file, because it's excluded from the 'war' phase. This allows <code>development-only</code> plugins to not be packaged for production use.<p class="paragraph"/>The full list of available scopes are defined by the enum <a href="https://grails.apache.org/docs/3.0.x/api/grails/util/BuildScope.html" class="api">BuildScope</a>, but here's a summary: |
| <ul class="star"> |
| <li><code>test</code> - when running tests</li> |
| <li><code>functional-test</code> - when running functional tests</li> |
| <li><code>run</code> - for run-app and run-war</li> |
| <li><code>war</code> - when packaging the application as a WAR file</li> |
| <li><code>all</code> - plugin applies to all scopes (default)</li> |
| </ul><p class="paragraph"/>Both properties can be one of: |
| <ul class="star"> |
| <li>a string - a sole inclusion</li> |
| <li>a list - a list of environments or scopes to include</li> |
| <li>a map - for full control, with 'includes' and/or 'excludes' keys that can have string or list values</li> |
| </ul><p class="paragraph"/>For example,<p class="paragraph"/><div class="code"><pre>def environments = <span class="java-quote">"test"</span></pre></div><p class="paragraph"/>will only include the plugin in the test environment, whereas<p class="paragraph"/><div class="code"><pre>def environments = [<span class="java-quote">"development"</span>, <span class="java-quote">"test"</span>]</pre></div><p class="paragraph"/>will include it in both the development <em class="italic">and</em> test environments. Finally,<p class="paragraph"/><div class="code"><pre>def environments = [includes: [<span class="java-quote">"development"</span>, <span class="java-quote">"test"</span>]]</pre></div><p class="paragraph"/>will do the same thing. |
| |
| |
| |
| <h2 id="artefactApi">18.10 The Artefact API</h2> |
| You should by now understand that Grails has the concept of artefacts: special types of classes that it knows about and can treat differently from normal Groovy and Java classes, for example by enhancing them with extra properties and methods. Examples of artefacts include domain classes and controllers. What you may not be aware of is that Grails allows application and plugin developers access to the underlying infrastructure for artefacts, which means you can find out what artefacts are available and even enhance them yourself. You can even provide your own custom artefact types. |
| |
| |
| |
| <h2 id="queryingArtefacts">18.10.1 Asking About Available Artefacts</h2> |
| As a plugin developer, it can be important for you to find out about what domain classes, controllers, or other types of artefact are available in an application. For example, the <a href="http://grails.org/plugin/searchable" target="blank">Searchable plugin</a> needs to know what domain classes exist so it can check them for any <code>searchable</code> properties and index the appropriate ones. So how does it do it? The answer lies with the <code>grailsApplication</code> object, and instance of <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsApplication.html" class="api">GrailsApplication</a> that's available automatically in controllers and GSPs and can be <a href="../guide/single.html#dependencyInjectionServices" class="guide">injected</a> everywhere else.<p class="paragraph"/>The <code>grailsApplication</code> object has several important properties and methods for querying artefacts. Probably the most common is the one that gives you all the classes of a particular artefact type:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">for</span> (cls in grailsApplication.<artefactType>Classes) { |
| … |
| }</pre></div><p class="paragraph"/>In this case, <code>artefactType</code> is the property name form of the artefact type. With core Grails you have: |
| <ul class="star"> |
| <li>domain</li> |
| <li>controller</li> |
| <li>tagLib</li> |
| <li>service</li> |
| <li>codec</li> |
| <li>bootstrap</li> |
| <li>urlMappings</li> |
| </ul><p class="paragraph"/>So for example, if you want to iterate over all the domain classes, you use:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">for</span> (cls in grailsApplication.domainClasses) { |
| … |
| }</pre></div><p class="paragraph"/>and for URL mappings:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">for</span> (cls in grailsApplication.urlMappingsClasses) { |
| … |
| }</pre></div><p class="paragraph"/>You need to be aware that the objects returned by these properties are not instances of <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html" class="api">Class</a>. Instead, they are instances of <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsClass.html" class="api">GrailsClass</a> that has some particularly useful properties and methods, including one for the underlying <code>Class</code>: |
| <ul class="star"> |
| <li><code>shortName</code> - the class name of the artefact without the package (equivalent of <code>Class.simpleName</code>).</li> |
| <li><code>logicalPropertyName</code> - the artefact name in property form without the 'type' suffix. So <code>MyGreatController</code> becomes 'myGreat'.</li> |
| <li><code>isAbstract()</code> - a boolean indicating whether the artefact class is abstract or not.</li> |
| <li><code>getPropertyValue(name)</code> - returns the value of the given property, whether it's a static or an instance one. This works best if the property is initialised on declaration, e.g. <code>static transactional = true</code>.</li> |
| </ul><p class="paragraph"/>The artefact API also allows you to fetch classes by name and check whether a class is an artefact: |
| <ul class="star"> |
| <li>get<type>Class(String name)</li> |
| <li>is<type>Class(Class clazz)</li> |
| </ul><p class="paragraph"/>The first method will retrieve the <code>GrailsClass</code> instance for the given name, e.g. 'MyGreatController'. The second will check whether a class is a particular type of artefact. For example, you can use <code>grailsApplication.isControllerClass(org.example.MyGreatController)</code> to check whether <code>MyGreatController</code> is in fact a controller. |
| |
| |
| |
| <h2 id="customArtefacts">18.10.2 Adding Your Own Artefact Types</h2> |
| Plugins can easily provide their own artefacts so that they can easily find out what implementations are available and take part in reloading. All you need to do is create an <code>ArtefactHandler</code> implementation and register it in your main plugin class:<p class="paragraph"/><div class="code"><pre>class MyGrailsPlugin { |
| def artefacts = [ org.somewhere.MyArtefactHandler ] |
| … |
| }</pre></div><p class="paragraph"/>The <code>artefacts</code> list can contain either handler classes (as above) or instances of handlers.<p class="paragraph"/>So, what does an artefact handler look like? Well, put simply it is an implementation of the <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/ArtefactHandler.html" class="api">ArtefactHandler</a> interface. To make life a bit easier, there is a skeleton implementation that can readily be extended: <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/ArtefactHandlerAdapter.html" class="api">ArtefactHandlerAdapter</a>.<p class="paragraph"/>In addition to the handler itself, every new artefact needs a corresponding wrapper class that implements <a href="https://grails.apache.org/docs/3.0.x/api/grails/core/GrailsClass.html" class="api">GrailsClass</a>. Again, skeleton implementations are available such as <a href="https://grails.apache.org/docs/3.0.x/api/org/grails/core/AbstractInjectableGrailsClass.html" class="api">AbstractInjectableGrailsClass</a>, which is particularly useful as it turns your artefact into a Spring bean that is auto-wired, just like controllers and services.<p class="paragraph"/>The best way to understand how both the handler and wrapper classes work is to look at the Quartz plugin: |
| <ul class="star"> |
| <li><a href="https://github.com/grails3-plugins/quartz/blob/master/src/main/groovy/grails/plugins/quartz/GrailsJobClass.java" target="blank">GrailsJobClass</a></li> |
| <li><a href="https://github.com/grails3-plugins/quartz/blob/master/src/main/groovy/grails/plugins/quartz/DefaultGrailsJobClass.java" target="blank">DefaultGrailsJobClass</a></li> |
| <li><a href="https://github.com/grails3-plugins/quartz/blob/master/src/main/groovy/grails/plugins/quartz/JobArtefactHandler.java" target="blank">JobArtefactHandler</a></li> |
| </ul><p class="paragraph"/>Another example is the <a href="http://github.com/pledbrook/grails-shiro" target="blank">Shiro plugin</a> which adds a realm artefact. |
| |
| |
| |
| <div style="clear:both;margin-top:15px;"></div> |
| |
| <div class="toc-item prev-left"><a href="../guide/security.html"><< <strong>17</strong><span>Security</span></a></div> |
| |
| <div class="toc-item next-right"><a href="../guide/spring.html"><strong>19</strong><span>Grails and Spring</span> >></a></div> |
| |
| <div style="clear:both"></div> |
| </div> |
| </td> |
| <td id="col2"> |
| <div class="local clearfix"> |
| <div class="local-title"> |
| <a href="../guide/index.html" target="mainFrame">Quick Reference</a> |
| <span class="toggle">(<a href="#" onclick="localToggle(); return false;">hide</a>)</span> |
| </div> |
| <div class="menu"> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Command Line</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/bug-report.html">bug-report</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/clean.html">clean</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/compile.html">compile</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/console.html">console</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-app.html">create-app</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-command.html">create-command</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-controller.html">create-controller</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-domain-class.html">create-domain-class</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-functional-test.html">create-functional-test</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-hibernate-cfg-xml.html">create-hibernate-cfg-xml</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-integration-test.html">create-integration-test</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-interceptor.html">create-interceptor</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-plugin.html">create-plugin</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-profile.html">create-profile</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-script.html">create-script</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-service.html">create-service</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-taglib.html">create-taglib</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/create-unit-test.html">create-unit-test</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/dependency-report.html">dependency-report</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/docs.html">docs</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/generate-all.html">generate-all</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/generate-controller.html">generate-controller</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/generate-views.html">generate-views</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/help.html">help</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/install-templates.html">install-templates</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/list-plugins.html">list-plugins</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/list-profiles.html">list-profiles</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/package-plugin.html">package-plugin</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/package.html">package</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/plugin-info.html">plugin-info</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/profile-info.html">profile-info</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/run-app.html">run-app</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/schema-export.html">schema-export</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/shell.html">shell</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/stats.html">stats</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/stop-app.html">stop-app</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/test-app.html">test-app</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Command%20Line/war.html">war</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Constraints</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Constraints/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Constraints/attributes.html">attributes</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/bindable.html">bindable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/blank.html">blank</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/creditCard.html">creditCard</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/email.html">email</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/inList.html">inList</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/matches.html">matches</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/max.html">max</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/maxSize.html">maxSize</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/min.html">min</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/minSize.html">minSize</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/notEqual.html">notEqual</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/nullable.html">nullable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/range.html">range</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/scale.html">scale</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/size.html">size</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/unique.html">unique</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/url.html">url</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/validator.html">validator</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Constraints/widget.html">widget</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Controllers</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Controllers/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Controllers/actionName.html">actionName</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/afterInterceptor.html">afterInterceptor</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/allowedMethods.html">allowedMethods</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/bindData.html">bindData</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/chain.html">chain</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/controllerName.html">controllerName</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/defaultAction.html">defaultAction</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/errors.html">errors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/flash.html">flash</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/forward.html">forward</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/grailsApplication.html">grailsApplication</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/hasErrors.html">hasErrors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/namespace.html">namespace</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/params.html">params</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/redirect.html">redirect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/render.html">render</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/request.html">request</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/respond.html">respond</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/response.html">response</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/responseFormats.html">responseFormats</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/scope.html">scope</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/servletContext.html">servletContext</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/session.html">session</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/withForm.html">withForm</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Controllers/withFormat.html">withFormat</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Database Mapping</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/autoImport.html">autoImport</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/autoTimestamp.html">autoTimestamp</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/batchSize.html">batchSize</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/cache.html">cache</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/cascade.html">cascade</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/column.html">column</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/comment.html">comment</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/discriminator.html">discriminator</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/dynamicInsert.html">dynamicInsert</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/dynamicUpdate.html">dynamicUpdate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/fetch.html">fetch</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/id.html">id</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/ignoreNotFound.html">ignoreNotFound</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/indexColumn.html">indexColumn</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/insertable.html">insertable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/joinTable.html">joinTable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/lazy.html">lazy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/order.html">order</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/sort.html">sort</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/table.html">table</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/type.html">type</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/updateable.html">updateable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Database%20Mapping/version.html">version</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Domain Classes</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/addTo.html">addTo</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/attach.html">attach</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/belongsTo.html">belongsTo</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/clearErrors.html">clearErrors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/constraints.html">constraints</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/count.html">count</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/countBy.html">countBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/createCriteria.html">createCriteria</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/delete.html">delete</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/discard.html">discard</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/embedded.html">embedded</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/errors.html">errors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/executeQuery.html">executeQuery</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/executeUpdate.html">executeUpdate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/exists.html">exists</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/fetchMode.html">fetchMode</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/find.html">find</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findAll.html">findAll</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findAllBy.html">findAllBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findAllWhere.html">findAllWhere</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findBy.html">findBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findOrCreateBy.html">findOrCreateBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findOrCreateWhere.html">findOrCreateWhere</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findOrSaveBy.html">findOrSaveBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findOrSaveWhere.html">findOrSaveWhere</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/findWhere.html">findWhere</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/first.html">first</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/get.html">get</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/getAll.html">getAll</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/getDirtyPropertyNames.html">getDirtyPropertyNames</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/getPersistentValue.html">getPersistentValue</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/hasErrors.html">hasErrors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/hasMany.html">hasMany</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/hasOne.html">hasOne</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/ident.html">ident</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/instanceOf.html">instanceOf</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/isAttached.html">isAttached</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/isDirty.html">isDirty</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/last.html">last</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/list.html">list</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/listOrderBy.html">listOrderBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/load.html">load</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/lock.html">lock</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/mapWith.html">mapWith</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/mappedBy.html">mappedBy</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/mapping.html">mapping</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/merge.html">merge</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/namedQueries.html">namedQueries</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/properties.html">properties</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/read.html">read</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/refresh.html">refresh</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/removeFrom.html">removeFrom</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/save.html">save</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/transients.html">transients</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/validate.html">validate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/where.html">where</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/whereAny.html">whereAny</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/withCriteria.html">withCriteria</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/withNewSession.html">withNewSession</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/withSession.html">withSession</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Domain%20Classes/withTransaction.html">withTransaction</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Plug-ins</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/URL%20mappings.html">URL mappings</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/codecs.html">codecs</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/controllers.html">controllers</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/core.html">core</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/dataSource.html">dataSource</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/domainClasses.html">domainClasses</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/hibernate.html">hibernate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/i18n.html">i18n</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/logging.html">logging</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/scaffolding.html">scaffolding</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/services.html">services</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Plug-ins/servlets.html">servlets</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Services</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Services/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Services/scope.html">scope</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Services/transactional.html">transactional</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Servlet API</h1><div class="menu-sub"> |
| |
| |
| <div class="menu-item"><a href="../ref/Servlet%20API/request.html">request</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Servlet%20API/response.html">response</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Servlet%20API/servletContext.html">servletContext</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Servlet%20API/session.html">session</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tag Libraries</h1><div class="menu-sub"> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/Usage.html">Usage</a></div> |
| |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/actionName.html">actionName</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/controllerName.html">controllerName</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/flash.html">flash</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/pageScope.html">pageScope</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/params.html">params</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/request.html">request</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/response.html">response</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/servletContext.html">servletContext</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tag%20Libraries/session.html">session</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tags</h1><div class="menu-sub"> |
| |
| |
| <div class="menu-item"><a href="../ref/Tags/actionSubmit.html">actionSubmit</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/actionSubmitImage.html">actionSubmitImage</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/applyLayout.html">applyLayout</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/checkBox.html">checkBox</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/collect.html">collect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/cookie.html">cookie</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/country.html">country</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/countrySelect.html">countrySelect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/createLink.html">createLink</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/createLinkTo.html">createLinkTo</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/currencySelect.html">currencySelect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/datePicker.html">datePicker</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/each.html">each</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/eachError.html">eachError</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/else.html">else</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/elseif.html">elseif</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/external.html">external</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/field.html">field</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/fieldError.html">fieldError</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/fieldValue.html">fieldValue</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/findAll.html">findAll</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/form.html">form</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/formatBoolean.html">formatBoolean</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/formatDate.html">formatDate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/formatNumber.html">formatNumber</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/grep.html">grep</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/hasErrors.html">hasErrors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/header.html">header</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/hiddenField.html">hiddenField</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/if.html">if</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/img.html">img</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/include.html">include</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/isAvailable.html">isAvailable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/isNotAvailable.html">isNotAvailable</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/javascript.html">javascript</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/join.html">join</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/layoutBody.html">layoutBody</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/layoutHead.html">layoutHead</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/layoutTitle.html">layoutTitle</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/link.html">link</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/localeSelect.html">localeSelect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/message.html">message</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/meta.html">meta</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/pageProperty.html">pageProperty</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/paginate.html">paginate</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/passwordField.html">passwordField</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/radio.html">radio</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/radioGroup.html">radioGroup</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/render.html">render</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/renderErrors.html">renderErrors</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/resource.html">resource</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/select.html">select</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/set.html">set</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/sortableColumn.html">sortableColumn</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/submitButton.html">submitButton</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/textArea.html">textArea</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/textField.html">textField</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/timeZoneSelect.html">timeZoneSelect</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/unless.html">unless</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/uploadForm.html">uploadForm</a> |
| </div> |
| |
| <div class="menu-item"><a href="../ref/Tags/while.html">while</a> |
| </div> |
| |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| </td> |
| </tr> |
| </table> |
| |
| <div id="footer"> |
| Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. |
| |
| </div> |
| |
| <script type="text/javascript" src="../js/docs.js"></script> |
| |
| </body> |
| </html> |