lundi 1 août 2016

Spring submit form get checkbox value not working

I cannot get "remember-me" checkbox value (getting 400 Required boolean parameter 'remember' is not present)

Trying to user @RequestParam. (as for inputs email/password). How to get checkbox value and not 400 error?

Controller


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private String doLogin(@RequestParam(value = "inputEmail") String inputEmail,
                           @RequestParam(value = "inputPassword") String inputPassword,
                           @RequestParam(value = "remember") boolean remember,
                           HttpSession session) {



HTML form

    <form class="form-login" method="post" action="/login">
                <h2 class="form-login-heading">Please log in</h2>
                <label for="inputEmail" class="sr-only">Email address</label>
                <input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required
                       autofocus>
                <label for="inputPassword" class="sr-only">Password</label>
                <input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="remember" value="remember-me"> Remember me
                    </label>
                </div>
                <button class="btn btn-lg btn-primary btn-block btn-login" type="submit">Log in</button>
            </form>




Aucun commentaire:

Enregistrer un commentaire