JSF 1.2的startElement和writeAttribute解释 [英] JSF 1.2 startElement and writeAttribute explanation
问题描述
我有机会为我的项目编写一些自定义渲染器,并且工作得很好。但是我对ResponseWriter方法中的一些参数感到有些困惑。文档没有很好地解释这一点,所以我希望其中一位常驻JSF专家可以更好地解释这一点。具体来说:
I've had occasion to write some custom renderers for my project and that's working perfectly well. However I am somewhat confused by some of the parameters in the ResponseWriter methods. The documentation doesn't explain this very well so I'm hoping one of the resident JSF experts can explain this better. Specifically:
public abstract void startElement(java.lang.String name,
javax.faces.component.UIComponent component)
throws java.io.IOException
Parameters:
name - Name of the element to be started
component - The UIComponent (if any) to which this element corresponds
第二个参数实际上做了什么?我是否在渲染器中传递null或this似乎工作正常?
What does that second parameter actually do? It seems to work fine whether i pass "null" or "this" in my renderer?
类似于writeAttribute:
Similarly for writeAttribute:
public abstract void writeAttribute(java.lang.String name,
java.lang.Object value,
java.lang.String property)
throws java.io.IOException
Parameters:
name - Attribute name to be added
value - Attribute value to be added
property - Name of the property or attribute (if any) of the UIComponent associated with the containing element, to which this generated attribute corresponds
为什么ResponseWriter需要知道后台属性吗?同样,如果我在编写class属性时传递null或styleClass,它似乎工作正常。
Why does the ResponseWriter need to know the backing property? Again, it seems to work fine if I pass null or, "styleClass" when writing the class attribute.
好奇的人想知道,我的google-fu失败了在这一个...
Curious minds want to know, and my google-fu is failing on this one...
推荐答案
标准的Mojarra实现与它们 nothing 。 startElement()
的组件
参数和属性
参数明确忽略 writeAttribute()
。
The standard Mojarra implementation does nothing with them. The component
argument of startElement()
and the property
argument of writeAttribute()
are plain ignored.
但是,可以提供自定义响应编写器。对于一些真实世界的实现,了解内部的 UIComponent
和/或关联的 UIComponent
属性是完全有意义的响应作者。
However, it's possible to provide a custom response writer. For some real world implementations it would make completely sense to know about the originating UIComponent
and/or the associated UIComponent
property inside the response writer.
虽然JSF 2.0是针对性的,但 OmniFaces的 Html5ResponseWriter
将是一个很好的例子。 startElement()
通过几个 instanceof $ c $确定
UIComponent
的类型c>在允许/编写某些特定HTML5属性之前进行检查。
Although JSF 2.0 targeted, the Html5ResponseWriter
of OmniFaces would be a good example. The startElement()
determines the type of the UIComponent
by several instanceof
checks before allowing/writing some specific HTML5 attributes.
这篇关于JSF 1.2的startElement和writeAttribute解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!