我检查了许多其他有类似问题的线程,但我找不到这个线程有什么问题。CDI @Named与@ManagedBean不冲突。这是我使用的bean类。
@Named
@RequestScoped
public class UserBean {
private String name;
public UserBean() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String addValuesToFlashAction() {
Flash flash = FacesContext.getCurrentInstance()
.getExternalContext().getFlash();
flash.put("name", name);
return "terms?faces-redirect=true";
}
public void pullValuesFromFlashAction(ComponentSystemEvent e) {
Flash flash = FacesContext.getCurrentInstance()
.getExternalContext().getFlash();
this.name = (String) flash.get(name);
}
...
}
这是xhtml索引页的正文
<h:body>
<f:metadata>
<f:event type="preRenderView"
listener="#{userBean.pullValuesFromFlashAction}"/>
</f:metadata>
<h:messages/>
<h:form>
Name: <h:inputText value="#{userBean.name}"/>
<h:commandButton value="Register"
action="#{userBean.addValuesToFlashAction()}"/>
</h:form>
</h:body>
当我运行这个,我有/flashIndex.xhtml @12,72 listener="#{userBean. html":目标不可达,标识符'userBean'解析为null,并且在glassfish日志中抛出javax.el.PropertyNotFoundException
已解决:我导入了javax.faces.bean。javax.enterprise.context.RequestScoped