Wednesday, October 18, 2017

Grails Bind Function | Method For Groovy Page View

Grails Bind Function | Method For Groovy Page View

Have to extend metaclass as below:


import org.codehaus.groovy.grails.web.pages.GroovyPage

GroovyPage.metaClass.with {
    xor = {
        "XOR-VALUE"
    }
    isTrue = { Map attrs = null ->
        println(attrs)
        return true
    }
}

And then you can use function/method in gsp page as below:


<h1>${xor()} ${isTrue(param1: 'value1', params2: 'value2') ? 'IS-TRUE' : 'IS-FALSE'}</h1>
<-- --="">

And output is as below:

XOR-VALUE IS-TRUE


No comments:

Post a Comment