【问题标题】:Why are composite component's attributes not working with Primefaces attributes?为什么复合组件的属性不能与 Primefaces 属性一起使用?
【发布时间】:2014-02-06 10:08:46
【问题描述】:

我使用 Primefaces 创建了一个复合组件,如下所示:

<composite:interface>
    <composite:attribute name="testText" />
</composite:interface>

<composite:implementation>
    <p:button id="testid#{cc.attrs.testText}" value="#{cc.attrs.testText}"
              widgetVar="testWidgetVar#{cc.attrs.testText}" />
</composite:implementation>

当我使用带有属性 testText="test" 的自定义组件时

我得到以下行为:

  • “test”显示在按钮上(如预期的那样)

  • 按钮组件的id是“testidtest”(如预期),

  • 但 widgetVar 不是如预期的那样“testWidgetVartest”!

菜单组件的调试输出如下:

<Button disableClientWindow="false" disabled="false" escape="true" iconPos="left" id="testidtest" inView="true" includeViewParams="false" inline="false" rendered="true" target="_self" transient="false" widgetVar="testWidgetVar"/>

有人可以解释这种行为吗?

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    在 JSF 请求-响应周期中处理 id 和 widgetVar 属性时,EL 评估尚未准备好。

    一些相关链接:

    Why JSF calls getters multiple times

    EL evaluation in a JSF page is not sequential

    Javatutorial: JSF 2 Lifecycle

    【讨论】:

    • 抱歉,问题中有错误。 id 正确设置为 testidtest,只有 widgetVar 属性没有。我看不出这与生命周期或您提供的链接有何关联。
    【解决方案2】:

    现在我发现了问题:调试输出(Glassfish 4.0、Mojarra 2.2.0)有时无法正确显示属性的实际状态。 widgetVar 设置正确,可以在应用程序中使用,虽然它没有显示在调试输出中,所以问题只在调试输出中。我不明白为什么会这样。 我学到的唯一一课就是不要依赖调试输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 2011-08-13
      • 2021-04-27
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      相关资源
      最近更新 更多