Created
October 1, 2015 11:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
String bar | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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