Jsf 2 JSF中component.getAttributeName()和component.getAttributes().get(";name";)之间的区别是什么
在JSF中,两者之间有什么区别Jsf 2 JSF中component.getAttributeName()和component.getAttributes().get(";name";)之间的区别是什么,jsf-2,components,Jsf 2,Components,在JSF中,两者之间有什么区别 UIComponent component; component.get *AttributeName*() and component.getAttributes().get("attibute name") ? ? 例如,如果我在getAttributes()HashMap?的调用阶段设置disabled=true属性,则在功能上没有任何区别。从技术上讲,UIComponent#getAttributes()允许开发人员在获取/设置属性时不必担心确切的组
UIComponent component;
component.get *AttributeName*() and
component.getAttributes().get("attibute name")
?
?
例如,如果我在
getAttributes()
HashMap?的调用阶段设置disabled=true
属性,则在功能上没有任何区别。从技术上讲,UIComponent#getAttributes()
允许开发人员在获取/设置属性时不必担心确切的组件类型
使用disabled=“true”
查看您的特定示例。UIComponent
超类根本没有任何isDisabled()
方法。您需要先执行instanceof
检查,例如HtmlInputText
,然后才能对其进行强制转换并最终调用isDisabled()
。然后,getAttributes()
就更容易独立于此。标准jsfapi中的许多UIComponent
相关方法采用或返回UIComponent
超类,而不是特定类型
在正确设计的组件中,这两个组件最终都会委托给同一个组件,即
UIComponent\getstateheloper()
,谢谢您的回答。您能否用一些词解释一下UIComponent#getstateheloper()
用于什么?在同一视图上跨回发请求保存组件的状态。组件实例本质上是请求范围的。另见和
component.set *AttributeName*(value)
component.getAttributes().put("attibute name", value)