是否有可能知道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;
}
}
答案 0 :(得分:4)
您可以使用UIComponent#getCurrentComponent()
。
public String getColor() {
UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
// ...
return color;
}