Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing JSF components tag attribute values from a backing bean

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();
    }
}
like image 983
ali honarmand Avatar asked Nov 08 '25 10:11

ali honarmand


1 Answers

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.

like image 130
Pablo Avatar answered Nov 10 '25 02:11

Pablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!