目标无法访问,标识符'securityBean'已解析为null

时间:2014-09-08 08:50:52

标签: maven jsf jsf-2

嘿,我在jetty中运行我的应用程序时遇到了这个问题。 我用spring框架和maven在java上创建了一些应用程序web。

当我想尝试登录我的网站时,我收到了一个错误消息。

来自码头的错误日志:

javax.el.PropertyNotFoundException: /screens/login.xhtml @30,138 value="#{securityBean.userId}": Target Unreachable, identifier 'securityBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:91)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
at javax.faces.component.UIInput.validate(UIInput.java:953)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
at javax.faces.component.UIInput.processValidators(UIInput.java:693)
at javax.faces.component.UIForm.processValidators(UIForm.java:240)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)

这是我的login.xhtml:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui">

<f:view contentType="text/html">

<h:head>
    <title>igate web admin</title>
    <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>

    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/bootstrap/bootstrap.css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/bootstrap/bootstrap.min.css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/bootstrap/bootstrap-theme.css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/bootstrap/bootstrap-theme.min.css" />
    <ui:insert name="head"></ui:insert>
</h:head>

<h:body>
    <div class="container">
        <h:form class="form-signin" role="form">
            <div class="logo"></div>
            <h2 class="form-signin-header" style="text-align: center; color: white"> LOGIN I-GATE</h2>
            <h:inputText class="form-control" required="true" requiredMessage="Username harus diisi" id="uname"  value="#{securityBean.userId}"/>
            <br></br>
            <h:inputSecret class="form-control" required="true" requiredMessage="Password harus diisi"  value="#{securityBean.password}"/>
            <button class="btn btn-lg btn-primary btn-block" type="submit" action="#{securityBean.login}" ajax="false">Sign in</button>
            <h4 style="text-align: center; color: white;">Please login with your Username and Password</h4>
        </h:form>
    </div>
</h:body>

这是我的securityPage.java:

@ManagedBean( name="securityBean" )

@SessionScoped

public class SecurityPage {

private String userId;
private String password;

private UserDao userDao;
private Logger log = Logger.getLogger( SecurityPage.class );

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getPassword() {
    return password;
}

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

/**
 * use to clear properties in this class
 * 
 */
private void clearPage() {

    this.userId = null;
    this.password = null;
}

/**
 * Executed to validate username and password
 * 
 * @return String
 */
public String login() {

    userDao = ( UserDao ) ServiceLocator.getService( "userDao" );

    try {

        String pass = Secure.digest( password );
        MUser user = userDao.login( userId, pass );

        if( user != null  ) {

            SessionUtil.setUserSession( user );
            SessionUtil.setObject( Constant.LOGIN_ROLENAME, user.getRoleName() );
        }
        else {

            FacesContext.getCurrentInstance().addMessage(
                "msgs",
                new FacesMessage( FacesMessage.SEVERITY_WARN,
                                  "User ID atau Password anda tidak valid.",
                                  "User ID atau Password anda tidak valid." ) );
                clearPage();

                return "login_failed";
        }
    } 
    catch( Exception e ) {

        FacesContext.getCurrentInstance().addMessage( 
                "msgs",
                new FacesMessage( FacesMessage.SEVERITY_WARN, 
                                  "User ID atau Password anda tidak valid.", 
                                  "User ID atau Password anda tidak valid." ) );
        clearPage();

        return "login_failed";
    }

    clearPage();

    return "login_success";
}

/**
 * Logout Action
 * 
 * Executed to invalidate session and logout user
 * 
 * @return String
 */
public String logout() {

    log.info( "user logout from application" );

    try {

        SessionUtil.invalidate();
    } 
    catch( Exception e ) {
        log.error( e );
    }

    return "/screens/login.jsf?faces-redirect=true";
}

}

我坚持这个问题。我试图遵循stackoverflow的另一个建议。但没人能解决这个问题。请帮忙:)

感谢。

0 个答案:

没有答案