The most common method expression/binding like closure you will use in Gracelets is most likely going
to be action closures. These can replace the 'action' attribute of most of the UICommand based components, like
the JSF Html CommandLink and CommandButton components.
Notice the following example:
Toggle Line Numbers |
1
h.form { 2
h.commandButton("Save Changes", action: { 3
someController.save(selectedEntity) 4
facesMessages.add("Your changes have been saved.") 5
}) 6
}
|
These work just like normal method expressions/bindings. For instance, in regards
to navigation, if you return a string from inside the closure, it will be used
to do noraml JSF navigation. So if there is a navigation rule or case matching the
outcome you return expect the navigation system to kick in.
Consider the following example:
Toggle Line Numbers |
1
h.dataTable (value: { someDataModel }, var: "row") { 2
... 3
h.column(facets: [header: { print "Options" }]) { 4
h.commandLink(action: { selectedEntity = row; "someOutcome"; }) { 5
h.graphicImage("images/editIcon.jpg") 6
} 7
} 8
... 9
}
|
Here we use an action closure to assign (or "outject") the selected record to the 'selectedEntity'
context variable. Then we return a string that will be used to navigate to the page where the
user could then edit the selected record.