4 Builder - Reference Documentation
Authors: groovyquan
Version: 0.5.1
4 Builder
Builders are internal DSLs that provide ease in working with certain types of problems.It is very useful for work with nested,hierarchical structures, such as tree structures, XML representations,or HTML representations.Let’s take a look at an example of one way to create zk component in Groovy—using a builder:4.1 appendChild
appendChild
is dynamic method that ZKUI injection to zk Component to begin builder,which accepts a Closure parameter.
def window = new Window(title: "listbox demo", border: "normal") window.appendChild { listbox { listhead(sizable: true) { listheader(label: "name", sort: "auto") listheader(label: "gender", sort: "auto") } listitem { listcell(label: "Mary") listcell(label: "FEMALE") } listitem { listcell(label: "John") listcell(label: "MALE") } listitem { listcell(label: "Jane") listcell(label: "FEMALE") } listitem { listcell(label: "Henry") listcell(label: "MALE") } listfoot { listfooter { label(value: "This is footer1") } listfooter { label(value: "This is footer2") } } } }
4.2 leftShift
ZKUI also provides a convenient methodleftShift
( << ),so you can modify the above code like:
def window = new Window(title: "listbox demo", border: "normal") window << { listbox { … } }
4.3 Event listening
If the parameter on onEvent it's a Closure, then it's a server side eventwindow << {
button(label: 'button', onClick: {
Messagebox.show("hello word! from Server")
})
}
4.4 Client-side event listening
If the parameter on onEvent it's a String, that is a client side eventwindow << {
button(label: 'buutton', onClick: "alert('Say hello word! from JS')")
}
client_
is useful when you also use server side event that avoid naming conflictswindow << { button(label: 'buutton', client_onClick: "alert('Say hello word! from JS')",onClick:{ Messagebox.show("hello word! from Server") }) }