2013-10-09 31 views
0

我是JSF的新手,無法弄清楚發生了什麼。
我不斷收到此錯誤:/index.xhtml @ 12,80值=「#{} LoginBean.username」:目標不可達,標識符「LoginBean」解析爲空JSF:/index.xhtml @ 12,80 value =「#{LoginBean.username}」:目標無法訪問,標識符'LoginBean'解析爲空

我已經分離出的問題降到這個...

的index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html"> 

    <h:head> 
     <title>JSF 2.0 LoginApp</title> 
</h:head> 
    <h:body> 
     <h2>JSF 2.0 Login App</h2><br/> 
     <h:form> 
      Username: <h:inputText id="username" value="#{LoginBean.username}"> //error here 
      </h:inputText> <br/><br/> 
      Password: <h:inputSecret id="password" value="#{LoginBean.password}"> //and error here 
      </h:inputSecret> <br/><br/> 
      <h:commandButton action="response.xhtml" value="Login" type="Submit"></h:commandButton> 
     </h:form> 


    </h:body> 
</html> 

response.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html"> 
    <h:head> 
     <title>Login Response</title> 
    </h:head> 
    <h:body> 
     <h:outputText id="result" escape="false" value="#{LoginBean.authenticate}"/> 
    </h:body> 
</html> 

LoginBean.java

public class LoginBean { 
private String username; 
private String password; 
} 

回答

0

確保您的loginBean注有@ManagedBean。如果您的類名稱是LoginBean那麼EL中的標識符將按照java慣例變爲loginBean,而不是LoginBean

2

你應該在jsf EL中修復你的bean名稱。我認爲你沒有給你的bean命名。因此在jsf EL中,你的bean名稱必須以小寫開頭。它是jsf的默認值。

變化value="#{LoginBean.username}"value="#{loginBean.username}"

0

確保你的bean擁有

  1. 註解@ManagedBean(請確保使用import javax.faces.bean.ManagedBean;)!
  2. 一個公共的無參數的構造
  3. getter和爲username setter和password
相關問題