如何获取调用托管bean的getter方法的UIComponent?

时间:2012-01-12 08:34:36

标签: jsf jsf-2

是否有可能知道UIComponent调用托管bean中某些属性的getter?

@ManagedBean
@SessionScoped
public class SomeBean {

    private String color;

    public String getColor() {
        // Here I would like to know which UIComponent called this method.
        return color;
    }

}

1 个答案:

答案 0 :(得分:4)

您可以使用UIComponent#getCurrentComponent()

public String getColor() {
    UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
    // ...

    return color;
}