Domanda

Ho veramente bisogno di aiuto su questo.

Sto avendo un semplice form di login nel file JSP, e cerco di usare JSF e gestiti fagioli con esso. Quando ho prima pagina il fuoco si sta visualizzando è contenuto, tuttavia quando premere il pulsante (h: commandButton) presentare. Sto ottenendo un errore

Qualcuno può dirmi che cosa è sbagliato con il mio codice?

errore:

javax.servlet.ServletException: javax.faces.FacesException: Expression Error: Named Object: Login not found.
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)

Ecco il mio JSP:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h:form id="login">
            <h:messages tooltip="true" />
            <h:inputText id="userNaME" required="true" requiredMessage="User name is required" value="#{Login.userName}" >
                <f:validator validatorId="Login" />
            </h:inputText><br />
            <h:inputSecret id="userPassword" required="true" value="#{Login.userPassword}" requiredMessage="User Password is required" /><br />
            <h:commandButton id="Login" title="Login" type="submit" action="#{Login.LoginUser}" />
            <h:message for="Login" style="color: green;" />
        </h:form>
    </body>
</html>
</f:view>

Il mio Bean Classe:

package myvalidators;

public class Login {
    private String _userName;
    private String _userPassword;

    public void setUserName(String userName)
    {
        this._userName = userName;
    }

    public String getUserName()
    {
        return this._userName;
    }

    public void setUserPassword(String userPassword)
    {
        this._userPassword = userPassword;
    }

    public String getUserPassword()
    {
        return this._userPassword;
    }

    public String LoginUser()
    {
        return this._userName;
        //going to perform a login here
    }
 }

E il mio faces-config xml

<managed-bean>
        <managed-bean-name>Login</managed-bean-name>
        <managed-bean-class>myvalidators.Login</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
È stato utile?

Soluzione

Questo è probabilmente il problema:

<f:validator validatorId="Login" />

Rimuovi il tag.

validatorId valore dell'attributo deve corrispondere al validatore-id elemento di una Validator registrato in faces-config.xml .

Altri suggerimenti

Non so molto di fagioli richiesti. U hanno cercato di cambiare per session bean? La mia ipotesi è che quei fagioli hanno bisogno di un po 'di inizializzazione che il codice manca.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top