John N
John N

Reputation: 854

What is difference in JSF between component.getAttributeName() vs. component.getAttributes().get("name")

What is difference in JSF between

UIComponent component;
component.get *AttributeName*()  and
component.getAttributes().get("attibute name") 

?

component.set *AttributeName*(value) 
component.getAttributes().put("attibute name", value) 

?

Make it any difference if I for example set disabled=true attribute in invoke phase in getAttributes() HashMap ?

Upvotes: 0

Views: 147

Answers (1)

BalusC
BalusC

Reputation: 1109432

Functionally, it doesn't make any difference. Technically, UIComponent#getAttributes() allows the developer to not worry about the exact component type while getting/setting the attributes.

Look at your particular example with disabled="true". The UIComponent superclass doesn't have any isDisabled() method at all. You'd need to perform an instanceof check on e.g. HtmlInputText before you can cast it and finally invoke isDisabled() on it. The getAttributes() is then much easier in order to be independent from that. A lot of UIComponent related methods in standard JSF API take or return UIComponent superclass instead of a specific type.

In properly designed components, both delegate under the covers ultimately to the same, the UIComponent#getStateHelper().

Upvotes: 1

Related Questions