Note that there are some explanatory texts on larger screens.

plurals
  1. POController @Mixin just works after recompile of running app
    text
    copied!<p>Within my latest grails 2.3.0 project I'm using the <code>@Mixin</code> annotation to mixin a helper class to keep my <code>controller</code> more DRY.</p> <p>The mixin is just working if a made some changes within the controller to force a recompile of the controller. After the initial compile (<code>grails run-app</code>) the helper isn't mixed in - I get a <code>MissingMethodException</code> trying to access a method from the helper class.</p> <p>Here is my helper witin <code>src/groovy</code>:</p> <pre><code>class ProjectHelper { def withProject(id, Closure c) { def project = Project.get(id) if (project) { c.call project } else { flash.message = 'Project not found!' render view: 'myView' return } } } </code></pre> <p>And (one of) the <code>controller</code> which uses the <code>ProjectHelper</code>:</p> <pre><code>@Mixin(ProjectHelper) class ProjectController { def index() { withProject params.projectId, {project -&gt; // do something with the project } } } </code></pre> <p>When I cleane the project using <code>grails clean</code> and starting the app, I get the following error after accessing <code>project/index</code>:</p> <pre><code>MissingMethodException occurred when processing request: [GET] /&lt;myApp&gt;/project/ No signature of method: &lt;myPackage&gt;.withProject() is applicable for argument types: (java.lang.String, &lt;myPackage&gt;.ProjectController$_index_closure1_closure10) values: [1, &lt;myPackage&gt;.ProjectController$_index_closure1_closure10@40d889b5] </code></pre> <p>After some changes in <code>ReportController</code> (e.g. adding a single space) grails compiles 2 source files and the method <code>withProject</code> could be used. Accessing <code>project/index</code> works as expected.</p> <p>What's going wrong here? Is it a bug or do I miss something?</p> <p><strong>Update</strong></p> <p>It turns out that I totally missed, that using the <code>grails.util.Mixin</code> gives me another exception (<code>MissingPropertyException</code>) due to missing access to the mixed in class properties (in my case: <code>flash</code>) (see <a href="http://jira.grails.org/browse/GRAILS-9905">JIRA this issue</a>) which is working with <code>groovy.lang.Mixin</code> (after recompile).</p> <p>Is there a way to manually recompile/inject/mixin the <code>groovy.lang.Mixin</code> at runtime or do I have to find another error handling for the <code>else</code> part till the issue is fixed?</p> <p>Any suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload