Accessing JSF components tag attribute values from

2020-07-23 05:09发布

I need to access a components tag attribute like:

<h:inputtext id="input_age"/>

from a backing bean, like:

public class UserInfo {
    String inputAgeId;
    public UserInfo() {
        inputAgeId = { /*code to access component tag attribute*/ }.getStyleClass();
    }
}

1条回答
来,给爷笑一个
2楼-- · 2020-07-23 05:56
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();

You can then use view.find("component_id") to get the right component. Once you have the component, you can use getAttributes() to get a Map<String, Object> with all the attributes of the component.

If you are accessing always the same compent, you can bind it to the backing bean instead.

查看更多
登录 后发表回答