2

即使在托管 Bean 中添加了 setter 方法,托管属性的值为 null。

@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;
    }

}  
4

0 回答 0