File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Griffon Lifecycle

 
Tom Patterson
Greenhorn
Posts: 3
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Ready.groovy script I would like to load some data into my view. My controller already has a closure to do this. However, I don't know how to reference my controller from the Ready.groovy script! I have been looking for examples of this and have come up empty. Any help would be appreciated!
 
Tom Patterson
Greenhorn
Posts: 3
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So no replies to my question. I was motivated to press in and figure it out on my own (With the help of Griffon In Action, the online Griffon Guide, and the Griffon API Documentation). Here it is:

The first thing I needed to know about was "app".

This is described in the following section of Griffon In Action:
5.1.1 Quick tour of injected properties and methods.
"The app property points to the current running application."

So now I know that the app is injected into the Ready.groovy script.

In the same section it says: "... by inspecting app.controllers and checking
for their type."

This is a good clue as to how I can get to my controller.

In section 6.3.1 I found the following: "The object that is used to access the portions is the app property. This property is unique from the other injectable properties in that it’s always available in MVC group members because Griffon injects its value at the metaclass level. It also implements the griffon.core.GriffonApplication interface."

So now I know that app implements griffon.core.GriffonApplication.

Online there is the very good Griffon Guide at:
http://griffon.codehaus.org/guide/1.4.0/guide/

In Chapter 11 (Resource Management) it talks about Resolving Configured Resources. It also has a link to griffon.core.GriffonApplication.

That link takes you to the Griffon API Documentation:
http://griffon.codehaus.org/guide/1.4.0/api/griffon/core/GriffonApplication.html

Of interest to me was the method summary:
Map getControllers()
Returns all currently available controller instances, keyed by group name.

Eureka! I can now get to my controller.

So I printed out the map that was returned by getControllers:
HyperTax
hypertax.HyperTaxController@927e4be

The first line is the key to my one and only controller.
The second line is the value of the controller instance (its reference)

So I still had to do a few more things:

I added the following import statement to Ready.groovy:
import hypertax.HyperTaxController

I then declared my controller:
HyperTaxController controller

I then assigned the value from the map to the controller variable.

Finally I called the controller method that accesses the database and populates the view:
controller.readTaxable()

Here's the complete Ready.groovy script:

import hypertax.HyperTaxController
/*
* This script is executed inside the UI thread, so be sure to call
* long running code in another thread.
*
* You have the following options
* - execOutsideUI { // your code }
* - execFuture { // your code }
* - Thread.start { // your code }
*
* You have the following options to run code again inside the UI thread
* - execInsideUIAsync { // your code }
* - execInsideUISync { // your code }
*/

Map controllerMap
HyperTaxController controller

controllerMap = app.getControllers()
controllerMap.each {entry ->
println entry.key
println entry.value
controller = entry.value
}

controller.readTaxable()

I hope this helps someone else out there that is wrestling with Griffon!

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We unfortunately do not have too many experts in this area which sometimes leads to lack of an answer. However, thank you for posting that detailed answer, which has now earned you a cow.
 
Tom Patterson
Greenhorn
Posts: 3
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran, thank you for the cow!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic