java - JSF 1.2 startElement 和 writeAttribute 解释

标签 java jsf jsf-1.2

我有机会为我的项目编写一些自定义渲染器,而且效果非常好。但是,我对 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/

相关文章:

java - 将数组结果存入数组

jakarta-ee - @EJB 注释与 JNDI 查找

jsf - 遍历 JSF 1.2 中的列表

JSF Siteminder 注销

jsf - PrimeFaces 3.2 DataTable "jump to page"分页器模板?

html - 命令按钮操作方法未执行

java - 我如何知道单元格在读取 Excel 工作表时是否返回空值?

java - 如何扩展 JPA 实体以仅添加组合

java - 如何使用java从oracle数据库获取以毫秒为单位的日期/时间?

javascript - 为什么我在 javascript 多行字符串中收到 "Error parsing..."?