Added Groovy example integrated on ItsNat in ItsNat Experiments

9 views
Skip to first unread message

Jose Maria Arranz Santamaria

unread,
Aug 13, 2013, 3:46:26 PM8/13/13
to its...@googlegroups.com

This example shows how we can use a dynamic language like Groovy to code the view logic of an ItsNat application instead of using Java.

Your ItsNat code will be similar to this:

package inexp.groovyex;

import org.w3c.dom.events.Event
import org.w3c.dom.events.EventListener

class GroovyExampleDocument
{
    def itsNatDoc // ItsNatHTMLDocument
    def textInput // ItsNatHTMLInputText
    def resultsElem // Element   

    GroovyExampleDocument(itsNatDoc)
    {
        this.itsNatDoc = itsNatDoc

        def doc = itsNatDoc.getHTMLDocument()
   
        def compMgr = itsNatDoc.getItsNatComponentManager()
        this.textInput = compMgr.createItsNatComponentById("inputId")
        
        def buttonElem = doc.getElementById("buttonId")
        buttonElem.addEventListener("click", 
             { Event evt -> def text = textInput.getText(); resultsElem.setTextContent(text); } as EventListener, false)

        this.resultsElem = doc.getElementById("resultsId")
    }
}

Unfortunately hot redeploy doesn't work because Groovy objects (listeners) are registered in and called by ItsNat Java classes, after any change to Groovy code you must redeploy the web app to make effective your changes.

See online and Source code (groovyex folders)

Enjoy.


Reply all
Reply to author
Forward
0 new messages