2

The Managed Property value is null even though the setter method is added in the Managed Bean.

@ManagedBean
@ViewScoped
@XmlRootElement(name = "name")
public class Name{
 private String firstName;

    public String getFirstName() {
      return firstName;
    }

    public void setFirstName(String firstName){
      this.firstName= firstName;
    }
}

@ManagedBean(eager=true)
@ViewScoped
public class Person{

    @ManagedProperty(value = "#{name}")
    private Name name;

     public String displayName(){       
       name.getFirstName(); //name is null
     }
    public void setName(Name name){
      this.name= name;
    }

}  
user679526
  • 845
  • 4
  • 16
  • 39
  • Where is code `name.getFirstName` located? This is really useless code here. – partlov Mar 18 '13 at 14:00
  • Did you specify a certain beanname for your managedbean "Name"? Maybe you named it "nameBean"? Is your setter defines like: "setName(Name ..)"? – Manuel Mar 18 '13 at 14:02
  • There is no beanname defined for managedBean Name. – user679526 Mar 18 '13 at 14:45
  • Is the *setName* method being called? If so, is the provided *name* Object null? – Manuel Mar 18 '13 at 14:46
  • displayName() method is called on the xhtml page. The setter method for Name is never called. The Name class is in a different project. Can this be the reason for null value? – user679526 Mar 18 '13 at 14:54
  • @BalusC: Name class is in a different project. This project does not have Faces-config defined. What all files are needed to identify the managed bean in this project? – user679526 Mar 19 '13 at 19:43
  • If `setName` never gets called, then that's the problem. That other project needs a `faces-config.xml` as well. You don't need the `eager` attribute I guess, check out what it means! – Manuel Mar 20 '13 at 15:25

0 Answers0