JSF 1.2的startElement和writeAttribute解释
我有机会为我的项目编写一些自定义渲染器,并且运行良好。 但是我对ResponseWriter方法中的一些参数感到有些困惑。 文档没有很好地解释这一点,所以我希望其中一位常驻JSF专家可以更好地解释这一点。 特别:
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”似乎工作正常?
对于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”,它似乎工作正常。
好奇的人想知道,而我的谷歌在这个问题上失败了……
标准的Mojarra实现对它们没有任何作用 。 startElement()
的component
参数和writeAttribute()
的property
参数被忽略。
但是,可以提供自定义响应编写器。 对于某些现实世界的实现,了解响应UIComponent
的原始UIComponent
和/或关联的UIComponent
属性是完全有意义的。
虽然JSF 2.0是针对性的,但Html5ResponseWriter
的Html5ResponseWriter就是一个很好的例子。 在允许/编写某些特定的HTML5属性之前, startElement()
通过几个instanceof
检查确定UIComponent
的类型。