我有机会为我的项目编写一些自定义渲染器,而且效果非常好。但是,我对 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 需要知道支持属性?同样,如果我在编写类属性时传递 null 或“styleClass”,它似乎工作正常。
好奇的人想知道,我的 google-fu 在这方面失败了......
最佳答案
标准的 Mojarra 实现对它们什么都不做。 startElement()
的 component
参数和 writeAttribute()
的 property
参数被完全忽略。
但是,可以提供自定义响应编写器。对于某些现实世界的实现,了解响应编写器中的原始 UIComponent
和/或关联的 UIComponent
属性是完全有意义的。
尽管以 JSF 2.0 为目标,Html5ResponseWriter
of OmniFaces将是一个很好的例子。在允许/写入一些特定的 HTML5 属性之前,startElement()
通过多个 instanceof
检查确定 UIComponent
的类型。
关于java - JSF 1.2 startElement 和 writeAttribute 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11810219/