【问题标题】:JSF 1.2 startElement and writeAttribute explanationJSF 1.2 startElement 和 writeAttribute 解释
【发布时间】:2012-08-02 08:35:25
【问题描述】:

我有机会为我的项目编写了一些自定义渲染器,并且效果很好。但是,我对 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 在这方面失败了......

【问题讨论】:

  • 据我了解,这些主要是为了调试目的,也许是为了一些奇怪的ResponseWriter 实现。标准的当然不在乎,我通常只是通过null 而不会打扰。

标签: java jsf jsf-1.2


【解决方案1】:

标准的 Mojarra 实现对它们什么都不做startElement()component 参数和 writeAttribute()property 参数被完全忽略。

但是,可以提供自定义响应编写器。对于某些现实世界的实现,了解响应编写器中的原始 UIComponent 和/或关联的 UIComponent 属性是完全有意义的。

尽管针对 JSF 2.0,Html5ResponseWriter of OmniFaces 将是一个很好的例子。 startElement() 在允许/写入某些特定的 HTML5 属性之前,通过几个 instanceof 检查来确定 UIComponent 的类型。

【讨论】:

  • 是的,我看了你非常好的 html5ResponseWriter 并在你的博客上留下了评论。我们越早升级到 WAS 8 和 JSF2.0 越好!
猜你喜欢
  • 2013-03-08
  • 2012-01-09
  • 2013-03-06
  • 2014-11-26
  • 2011-08-21
  • 2015-02-06
  • 2012-02-20
  • 2013-01-27
  • 2015-10-17
相关资源
最近更新 更多