Last active
October 20, 2015 20:53
-
-
Save Felipe00/ff369be71af5fd1db6ee to your computer and use it in GitHub Desktop.
Exemplo de view e controller para editar um objeto.
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
// Recebo o id da View | |
public Result update(Long id) { | |
Form<Local> editForm = localForm.bindFromRequest(); | |
//Busco o local pelo id (no banco) | |
Local localFromDb = Local.find.byId(id); | |
if (editForm.hasErrors()) { | |
LocalController.flashGlobalError(String.valueOf(editForm.get().getId())); | |
return badRequest(views.html.localEdit.render(localForm, id)); | |
} | |
Local local = editForm.get(); | |
//Seto o ID que veio como parâmetro no objeto que veio do form (assim não corre o risco de vir Null) | |
local.setId(id); | |
//Atualizo no banco | |
Ebean.update(local); | |
localForm.fill(new Local()); | |
//Redireciono para outra tela | |
return redirect(routes.LocalController.all()); | |
} |
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
@* Esse parâmetro "id" vem da view de Listagem. *@ | |
@(localForm: Form[Local], id: Long) | |
@import helper._ | |
@main("Service") { | |
<div class="card"> | |
<h5 class="teal-text center light">Editar Localidade</h5> | |
<div class="gray center"> | |
@tags.globalErrorByFlash() | |
</div> | |
@form(routes.LocalController.update(id), 'class -> "container") { | |
<div class="row"> | |
<div class="input-field col s6 center"> | |
<input type="text" id="name" name="name" required | |
value="@localForm.apply("name").value" /> | |
<label for="name">NOME DO LOCAL</label> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="input-field col s6"> | |
<button class="btn waves-effect waves-light right" type="submit" | |
name="action"> | |
Alterar | |
</button> | |
</div> | |
</div> | |
} | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ex.: vc deve ter uma action Edit, onde vc retorna um ok(views.html.localEdit.render(localForm, id))