Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testcommandobjects
- class TestController {
- static final int VALID = 5
- static final int INVALID = 50
- def resetToValid = { TestCommand cmd ->
- rebindAgeAndRenderResponse(cmd, true)
- }
- def resetToInvalid = { TestCommand cmd ->
- rebindAgeAndRenderResponse(cmd, false)
- }
- def gatherCommandData(cmd){
- [value: cmd as String,
- validates: cmd.validate()]
- }
- def rebindAgeAndRenderResponse(cmd, boolean changeToValid) {
- def value = changeToValid ? VALID : INVALID
- def before = gatherCommandData(cmd)
- bindData(cmd, [age: value])
- def after = gatherCommandData(cmd)
- render buildOutput(before, after)
- }
- def buildOutput(before, after) {
- def writer = new StringWriter()
- def builder = new groovy.xml.MarkupBuilder(writer)
- builder.html {
- head {
- title 'dataBind demo'
- }
- body {
- h1 'dataBind demo'
- h3 'valid data for age: 5..10'
- p "$before"
- p "$after"
- }
- }
- writer.toString()
- }
- }
- class TestCommand {
- static constraints = {
- age(range: 5..10)
- }
- int age
- String toString() {
- "age:[$age]"
- }
- }
Add Comment
Please, Sign In to add comment