So let pick a UIComponent like HtmlSelectOneRadio(Please view source here: http://grepcode.com/file/repo1.maven.org/maven2/com.sun.faces/jsf-api/2.1.7/javax/faces/component/html/HtmlSelectOneRadio.java#HtmlSelectOneRadio)
So some of the setters will call method handleAttribute(...), and some does not, for example
public void setDir(java.lang.String dir) {
getStateHelper().put(PropertyKeys.dir, dir);
handleAttribute("dir", dir);
}
public void setDisabled(boolean disabled) {
getStateHelper().put(PropertyKeys.disabled, disabled);
}
and it is very UNCLEAR to me what handleAttribute is doing, can a JSF guru please explain to me what this method try accomplish and why somes attribute call this method while other does not? Thank you so much
It’s related to Mojarra-internal rendering optimizations, wherein only the attributes which are been set by the internal
handleAttribute()method are been rendered as so-called “pass-thru” attributes instead of that every single attribute of the component will be checked if it has been set or not, which may end up to be more expensive if there are relatively a lot of attributes. A “pass-thru” attribute is a component attribute which can just be outright rendered without any specific pre/postprocessing.Peek around in Mojarra’s
RenderKitUtilsclass, starting at therenderPassThruAttributes()method:The
canBeOptimized()returnstrueif thecomponentis one of the standard JSF components (actually, if the component’s package name starts withjavax.faces.component.) and if there is no more than 1 behavior in thebehaviorsarray.The
renderPassThruAttributesOptimized()will only render the attributes which are specified insetAttributesargument.The
renderPassThruAttributesUnoptimized()will loop through every single attribute in theattributesmap and check for every single attribute if the associated value is not null/empty and then render it.As to why some attributes are not been set by
handleAttribute(), that’s because they require some more specific pre/postprocessing and are already explicitly been rendered by the renderer specific to the component, so they don’t need to be rendered as a “pass-thru” attribute.You don’t need to worry about this when writing custom components. You can always introduce your own optimizations similar to this, but it isn’t recommend to rely on Mojarra-specific internal optimizations as they may not work at all when you’re using MyFaces, for example.