我正在使用 Eclipse 靛蓝。我正在关注这个站点的一个模式,它将 bean 分成 5 个类,我正在使用ModelBean
和。BackingBean
ControllerBean
我的项目结构是:
Java resources
-> src
->com.erp3.gui.user
上面提到的那些豆子
这是我的用户控制器
package com.erp3.gui.user;
import java.io.Serializable;
import com.erp3.bo.user.UserBO;
public class UserController implements Serializable {
private static final long serialVersionUID = 1L;
private UserBO bo;
private UserModel model;
public UserController() {
bo = new UserBO();
model = new UserModel();
}
public void Login() {
model.setVo(bo.executeLogin(model.getVo()));
System.out.println("Foi");
}
public UserBO getBo() {
return bo;
}
public void setBo(UserBO bo) {
this.bo = bo;
}
public UserModel getModel() {
return model;
}
public void setModel(UserModel model) {
this.model = model;
}
}
当我运行index.html
:
<h:inputText label="Usuário" id="username" value="#{userController.model.vo.login}"/>
我有这个例外:
javax.servlet.ServletException: Unable to create managed bean userController. The following problems were found:
- Bean or property class com.erp3.gui.user.UserController for managed bean userController cannot be found.
- Bean or property class com.erp3.gui.user.UserController for managed bean userController cannot be found.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
有人告诉我 Eclipse 不能使用注释,所以我有我的faces-config
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>userController</managed-bean-name>
<managed-bean-class>com.erp3.gui.user.UserController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>userBacking</managed-bean-name>
<managed-bean-class>com.erp3.gui.user.UserBacking</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>userModel</managed-bean-name>
<managed-bean-class>com.erp3.gui.user.UserModel</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<application>
<message-bundle>com.erp3.gui.helpers.messages</message-bundle>
</application>
</faces-config>
如有必要,我可以添加我的其他豆子,没有这样做,因为会提出一个巨大的问题
编辑
我在我的 bean 上添加了注释,问题变为:
javax.el.PropertyNotFoundException: /views/user/login.xhtml @18,135 value="#{userController.model.vo.login}": Target Unreachable, identifier 'userController' resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:91)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
javax.faces.component.UIInput.validate(UIInput.java:953)
javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
javax.faces.component.UIInput.processValidators(UIInput.java:693)
javax.faces.component.UIForm.processValidators(UIForm.java:240)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
但是当我将 bean 添加到faces-config
错误时,错误又回来了。