由于某种原因,我的xhtml页面找不到我的CDI托管bean。我已经看到了很多关于这个问题的资源(Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable),但我仍然没有解决这个问题。
这是我正在注入的Bean。
import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
@SessionScoped
@Named
public class MyMB implements Serializable{
private Integer max;
private static final long serialVersionUID = 1L;
public MyMB(){
super();
max = 1;
}
public void setMax(Integer max) {
this.max = max;
}
public Integer getMax(){
return this.max;
}
public String priority(){
return "priority";
}
}
这是我注射的地方。
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@SessionScoped
public class MyBean implements Serializable {
private static final long serialVersionUID = 1L;
String name = "myBean";
@Inject
private MyMB myMB;
MyMB getMyMB(){
return myMB;
}
}
这是我的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:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<h:outputStylesheet library="css" name="todo.css" />
<title>bean settings</title>
</h:head>
<body>
<h:outputText value="Edit myBean"/>
ManagedBean is: #{myBean.name}
<h:form>
<h:inputText value="#{myBean.myMB.max}"
converterMessage="Only numbers please" />
<h:commandButton value="Speichern" type="submit" action="#{myBean.myMB.priority}" />
</h:form>
</body>
</html>
由于某种原因,xhtml页面似乎找不到myBean类 我收到此错误消息。
/myPage.xhtml @ 20,105 value =“#{myBean.myMB.max}”:目标无法访问,标识符'myBean'已解析为null