JSF Form Attribute nicht an Bean übergeben

687b46c0da97

Mitglied
Hallo,
leider sehr unangenehm, aber ich find leider den Fehler nicht.
Ich habe eine JSF Applikation, in welcher die Parameter aus der Form (anscheinend) nicht an die Bean übergeben werden (email & password sind null).

View:

XML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</h:head>
<h:body>
    <div id="container">
        <div id="content">
            <h:form>
                <h:messages globalOnly="true" style="color:red;margin:8px;" />
                <h:panelGrid columns="2">
                    <h:outputLabel for="email">Username:</h:outputLabel>
                    <h:inputText id="email" value="#{loginController.email}"/>
                    <h:outputLabel for="password">Password:</h:outputLabel>
                    <h:inputSecret id="password" value="#{loginController.password}"/>
                </h:panelGrid>
                <h:commandButton value="Login" action="#{loginController.performLogin()}"/>
            </h:form>
        </div>
    </div>
</h:body>
</html>

Bean:
Java:
package test.jsf.controller.authentication;

import test.exception.AuthenticateUserException;
import test.web.facade.UserService;

import javax.faces.application.FacesMessage;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

@SessionScoped
@Named("loginController")
public class LoginController {

    @Inject
    private UserService userService;

    private String email;
    private String password;

    public String performLogin(){
        FacesContext context = FacesContext.getCurrentInstance();
        try {
            var user = userService.authenticateUser(email, password);
            if(user != null){
                context.getExternalContext().getSessionMap().put("user", user);
                context.addMessage(null, new FacesMessage("Auth succeeded"));
            }
        }catch(AuthenticateUserException aue){
            context.addMessage(null, new FacesMessage("Auth failed"));
        }catch(Exception e){
            context.addMessage(null, new FacesMessage("General Error"));
        }
        return "index";
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

performLogin wird korrekt aufgerufen, leider sind email und password null. Jemand eine Idee?
 

Neue Themen


Zurück
Oben