JSF无法使用Eclipse创建托管bean X.

时间:2012-05-18 13:37:35

标签: eclipse jsf javabeans

我正在使用Eclipse Indigo。我正在关注来自this网站的模式,它将5个类中的bean分开,我正在使用ModelBeanBackingBeanControllerBean

我的项目结构是:

Java resources - > src - > com.erp3.gui.user使用上面提到的那些bean

这是我的 UserController

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时,错误就会恢复。

2 个答案:

答案 0 :(得分:5)

不幸的是,这是一种极度缺乏关注。

在我的项目构建路径上,我引用了服务器上的jar,另一个程序员更改了这些jar地址,因此我打破了引用。

奇怪的是Eclipse没有发出有关此问题的任何警报。

问题解决了。

感谢BalusC和Montolide的时间和关注。

答案 1 :(得分:2)

Eclipse可以使用注释(或者可能是JBoss工具吗?),所以你应该在你的类上使用@ManagedBean

您的faces-config是否在WEB-INF文件夹中?