Accessing JSF components tag attribute values from a backing bean

人盡茶涼 提交于 2019-12-21 20:19:42

问题


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:


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.



来源:https://stackoverflow.com/questions/11061356/accessing-jsf-components-tag-attribute-values-from-a-backing-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!