Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2018 11:32
Show Gist options
  • Save anonymous/63b6f2a58d02e8d689437f6704c65147 to your computer and use it in GitHub Desktop.
Save anonymous/63b6f2a58d02e8d689437f6704c65147 to your computer and use it in GitHub Desktop.
Chamando um método do Controller através da View - Play framework
@import helper._
@form(action = routes.SeuController.login()) {
<input type="email" id="email" name="email" />
<input type="password" id="password" name="password" />
<button type="submit">ACESSAR SISTEMA</button>
}
public class LoginForm extends Model {
private String email;
private String password;
// Getters and Setters
...
}
#Arquivo de rotas
# ... Outras rotas aqui
GET /login controllers.SeuController.login
public class SeuController extends Controller {
private Form<LoginForm> loginForm;
@Inject
public SeuController(FormFactory formFactory) {
this.loginForm = formFactory.form(LoginForm.class);
}
public Result login() {
// Pega o objeto Form do request da view
Form<LoginForm> filledForm = loginForm.bindFromRequest();
// Extraio o objeto LoginForm do meu form da view
final LoginForm loginForm = filledForm.get();
// Faz algo com o objeto LoginForm, tipo salvar;
loginForm.save()
return ok();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment