Created
January 21, 2018 11:32
-
-
Save anonymous/63b6f2a58d02e8d689437f6704c65147 to your computer and use it in GitHub Desktop.
Chamando um método do Controller através da View - Play framework
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
@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> | |
} |
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
public class LoginForm extends Model { | |
private String email; | |
private String password; | |
// Getters and Setters | |
... | |
} |
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
#Arquivo de rotas | |
# ... Outras rotas aqui | |
GET /login controllers.SeuController.login |
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
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