Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay! 2.1-RC2 JavaForms validate() without static references
    primarykey
    data
    text
    <p>I've been going through the Play! 2.1 example to setup a basic login system following the ZenTasks example. Where I get stuck is the JavaForms part. I want to validate the login request using an instance of an auth service that is provided via Guice DI.</p> <p>I'm following <a href="https://github.com/playframework/Play20/blob/master/samples/java/zentasks/app/controllers/Application.java#L19" rel="nofollow">Play20 Sample</a>. This example uses a static <code>authenticate()</code> method to run the authentication when form validation is requested after form submission. Any thoughts on how to perform this validation step in a non-static scope?</p> <p>Note: I have looked at the Play! Authenticate plugin as well as the SecureSocial plugin, however those projects are overkill for what I want to do right now. Also, I am interested in a general solution for allowing non-static validation in JavaForms.</p> <p><strong>Edit:</strong> It seems there is some confusion about what I am asking for here. What I am hoping to find is an alternate way to perform the validation step of the form submission that is sent by a Play! framework Form.form() generated form. Currently it requires that a validate() method be called on an instance of a POJO which is not created through the DI framework. This results in static references being required to access authorization services etc...</p> <p><strong>Edit 2:</strong> The current solution I am working with is this:</p> <pre><code>public static class AuthServiceFormReference { @Inject public static Provider&lt;AuthService&gt; authService; } // In my auth module configure() //... requestStaticInjection(AuthController.AuthServiceFormReference.class); //... public static class Login { @Required public String email; @Required public String password; public String validate(){ if(AuthServiceFormReference.authService.get().authenticateAdmin(email, password) == null) { return "Invalid user or password"; } return null; } } </code></pre> <p>It's an okay workaround, but it still relies on static injection :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload