Search code examples
eclipsejsftomcat7myfaces

Managed Beans not getting deployed with the rest of the application


Enviornment:

  • IDE: Eclipse 3.7
  • Server: Tomcat 7.0
  • JSF 2.0

I am new to JSF and recently started having a strange problem when I try to deploy an application.

For some reason everything gets deployed except for the beans. This started when I noticed that no matter what I did, I couldn't access a newly created bean from a facelet. Then I noticed that I also couldn't use new functions that were created in old beans.

I did a little experiment where I took an existing setter method in my login bean, and changed it from:

public void setName(String name) {
    this.name = name;
}

to

public void setName(String name) {
    this.name = "not what was typed";
}

But the value that was retrieved from the bean on the next page was the value that I typed into the login form.

I think my faces-config.xml and web.xml files are both set up correctly. I googled the problem and the only thing that I found was that adding @ManagedBean and @SessionScope annotations before the bean declarations may help with older versions of JSF, but it didn't work.

I have tried creating a new server, and re-creating the project, but that did not help either. Here is the error that I am getting with my new project (which has all the same files as the old project, files created properly, and contents pasted in):

An Error Occurred:

javax.el.PropertyNotFoundException: /login.xhtml at line 21 and column 42 value="#{loginBean.name}": Property 'name' not found on type com.tutorial.LoginBean

Caused by:
javax.el.PropertyNotFoundException - /login.xhtml at line 21 and column 42 value="#{loginBean.name}": Property 'name' not found on type com.tutorial.LoginBean

Here is the login bean:

/**
* LoginBean.java
* 
*/

package com.tutorial;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean {
private String name;
private String password;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public void savePerson(ActionEvent actionEvent) {
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Welcome "
            + name + " " + password + "!"));
}
}

And here we have a fragment from login.xhtml, which uses the variables in LoginBean

    <ui:define name="sideBar">
        <p:accordionPanel multiple="true" activeIndex="0,1">
            <p:tab title="Login" id="loginTab">
                <h:form>
                    <h:panelGrid columns="1" style="width: 179px;" class="noBorder">
                        <h:outputLabel for="username" value="Username"></h:outputLabel>
                        <p:message for="username" id="msgUsername" />
                        <h:inputText id="username" value="#{loginBean.name}"
                            required="true" label="Username"></h:inputText>

                        <h:outputLabel for="password" value="Password"></h:outputLabel>
                        <p:message for="password" id="msgPassword" />
                        <h:inputSecret id="password" value="#{loginBean.password}"
                            required="true" label="Password">
                        </h:inputSecret>
                        <h:commandButton action="login"></h:commandButton>
                    </h:panelGrid>
                </h:form>
            </p:tab>
            <p:tab title="Information">
                Blah blah blah.

            </p:tab>
        </p:accordionPanel>
    </ui:define>

Anyone know what the problem is?

Sorry for the lengthy post.


Solution

  • Did you clean all existing compiled code? Seems like there are some old classes hanging around. That sometimes happens when using eclipse.

    Could also be that the tomcat classpath is different from the eclipse class path.