user745235
user745235

Reputation:

JSF Unable to create managed bean X using Eclipse

I'm using Eclipse Indigo. I'm following a patter from this site where it separates the beans in 5 classes, I'm using ModelBean, BackingBean and ControllerBean.

My project structure is:

Java resources -> src -> com.erp3.gui.user with those beans mentioned above

Here is my 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;
    }   
}

When I run the index.html:

<h:inputText label="Usuário" id="username" value="#{userController.model.vo.login}"/>

And I have this exception:

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)

I was told that Eclipse doesn't work with annotation, so I have my 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>

If necessary, I can add my other beans, didn't do because would make a enormous question

EDIT

I have added the annotations on my beans and the problem changed to:

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)

But when I add the beans to the faces-config the error comes back.

Upvotes: 1

Views: 8312

Answers (2)

user745235
user745235

Reputation:

Unfortunately it was a tremendous lack of attention.

On my project Build Path I was referencing to jars on my server and another programmer changed those jars addresses so I had broken references.

The weird is that Eclipse haven't send any alert about this issue.

Problem solved.

Thanks BalusC and Montolide for your time and attention.

Upvotes: 5

Montolide
Montolide

Reputation: 792

Eclipse works fine with annotations (or maybe its JBoss tools?), so you should use @ManagedBean on your class.

Are your faces-config on WEB-INF folder?

Upvotes: 2

Related Questions