我有机会为我的项目编写一些自定义渲染器,并且运行得非常好。然而,我对 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”,它似乎工作正常。
好奇的人想知道,而我的谷歌在这方面失败了......
标准 Mojarra 实现确实nothing跟他们。这component
的论证startElement()
和property
的论证writeAttribute()
被简单地忽略了。
但是,可以提供自定义响应编写器。对于一些现实世界的实现来说,了解原始数据是完全有意义的。UIComponent
和/或相关的UIComponent
响应编写器内的属性。
尽管 JSF 2.0 的目标是Html5ResponseWriterOmniFaces 的 http://showcase.omnifaces.org/renderkits/Html5RenderKit将是一个很好的例子。这startElement()
决定了的类型UIComponent
由几个instanceof
在允许/写入某些特定 HTML5 属性之前进行检查。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)