You are hereAria User Guide / Section III: In Depth / Scripting
Scripting
Scripting should be a natural complement to Aria. With most of the plumbing taken care of by the framework there is normally very little Java code, but even so having the extra capabilities of a language such as Groovy should be useful in simplifying application development in certain domains.
Being able to modify and execute quickly without reloading the application could be a real time saving during development.
Aria has had scripting support for some time, but it was limited to the valuation of attributes and scripts invoked via the attribute evaluation. With the new scripting support the complete page functionality can be implemented by a script and not only is this support more extensive but it is also simpler as the script methods do not need to be explicitly identified as script methods within the page XML. The new scripting support extends the script engine approach used in Aria 3 and it should not be a huge leap to provide JSR 223 support.
Adding Groovy Support
To use the new support the appropriate builder must first be added to the project..
Setting up the Groovy Builder
NumBuilderClasses=1</P> <P> BuilderClass0=org.formaria.scripts.groovy.GroovyBuilder
Once the builder has been loaded Aria will search fro .groovy files to implement the page class, just as it would search for a .class file if the page was implemented as Java. The page builder will also check if the script has been modified since the last load, and if it has the script will be reparsed. Reloading the script means that you can easily change the behavior of a running application. Thus the page can be declared as normal:
Declaring a page to use a Groovy script
<?xml version="1.0" encoding="UTF-8"?> <Page class="aria.groovy.Welcome.groovy"> <Components> <Button name="nextBtn" x="100" y="100" w="100" h="20" content="Next"/> </Components> <Events> <Event target="nextBtn" method="next" type="ActionHandler"/> </Events> </Page>
note that the class attribute of the page now points to a Groovy file. The Groovy is then as follows:
A Groovy page script
package aria.groovy; import org.formaria.aria.Page; public class Welcome { Page page; public Welcome() { } public void pageCreated() { println "pageCreated invoked" } public void next() { println "next invoked once again..." page.showPage( "MiddlePage" ); } }
The project also needs to be modified to add the Groovy jar files - choose those jars you need or choose the
groovy-all
jar.
- Printer-friendly version
- Login or register to post comments