Skip to content

Instantly share code, notes, and snippets.

@magnomp
Created October 1, 2015 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnomp/76cc97c85259196181bf to your computer and use it in GitHub Desktop.
Save magnomp/76cc97c85259196181bf to your computer and use it in GitHub Desktop.
Mantendo dados em formulário após submissão com erro em Grails
<g:form action="save">
<input type="hidden" name="foo.id" value="foo?.id"/>
<input type="version" name="foo.version" value="foo?.version"/>
<input type="text" value="foo.bar" value="foo?.bar"/>
<input type="submit"/>
</g:form>
class Foo {
String bar
}
class FooController {
def create() {
render view: 'create'
}
def edit(Long id) {
def foo = Foo.get(id)
if (foo)
render view: 'create', model: [foo: foo]
else {
flash.message = "Foo não encontrado"
redirect action: 'list'
}
}
def save(Foo foo) {
if (foo.save()) {
flash.message = "Foo salvo com sucesso"
redirect action: 'list'
}
else
render view: 'create', model: [foo: foo]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment