我一直在尝试从 xhtml 页面获取字段并将其存储在 bean 中。然后,将输入的字段加载到输出表单中。
Login.java(托管 Bean)
package com.ose.bookstore.model.entity;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Entity implementation class for Entity: Login
*
*/
@Entity
@ManagedBean(name="login")
public class Login implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private int loginId;
private String userEmail;
private String password;
private String secPassword;
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSecPassword() {
return secPassword;
}
public void setSecPassword(String secPassword) {
this.secPassword = secPassword;
}
public int getLoginId() {
return loginId;
}
public void setLoginId(int loginId) {
this.loginId = loginId;
}
}
Login.xhtml(输入表单)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p ="http://primefaces.org/ui">
<body>
<h:form>
<h:panelGrid>
<h:outputLabel value="User Name" />
<h:inputText value="#{login.userEmail}" />
<h:outputLabel value="Password" />
<h:inputText value="#{login.password}" />
<h:outputLabel value="sec Password" />
<p:inputText value="#{login.secPassword}" />
<h:commandButton value="Sign In"
action="confirmation.xhtml" />
</h:panelGrid>
</h:form>
</body>
</html>
确认.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p ="http://primefaces.org/ui">
<body>
<h:form>
<h:panelGrid>
<h:outputLabel value="User Name" />
<h:outputText value="#{login.userEmail}" />
<h:outputLabel value="Password" />
<h:outputText value="#{login.password}" />
<h:outputLabel value=" sec Password" />
<h:outputText value="#{login.secPassword}" />
</h:panelGrid>
</h:form>
</body>
</html>
每次运行此程序时,都会出现此错误: javax.el.PropertyNotFoundException: /Login.xhtml @16,46 value="#{login.userEmail}": Target Unreachable, identifier 'login' resolve to null
如何修复此错误?代码有问题吗?