【问题标题】:JSF 2.0: Passing composite component attribute to inner composite componentJSF 2.0:将复合组件属性传递给内部复合组件
【发布时间】:2011-06-02 21:49:36
【问题描述】:

我有以下情况:

<cc:interface>
    <cc:attribute name="someValue" />
</cc:interface>

<cc:composite>
    <x:someComponent>
        <span>#{cc.attrs.someValue}</span>
    </x:someComponent>
</cc:composite>

所以在我的复合组件内部,我正在调用其他复合组件并尝试将给“主”复合组件的参数传递给内部复合组件。

这失败了,因为在x:someComponent 标记内,cc 隐式对象似乎引用了这个x:someComponent

一种解决方法是为x:someComponent 创建一个临时字段,这样可以实现:

<x:someComponent passthroughField="#{cc.attrs.someValue}">
    <span>#{cc.attrs.passthroughField}</span>
</x:someComponent>

然而,这非常丑陋和不方便。

还有其他方法可以解决这个问题吗?

【问题讨论】:

    标签: jsf jsf-2 facelets composite-component


    【解决方案1】:

    解决此问题的一种方法是使用ui:param,如下所示:

    <ui:param name="foo" value="cc.attrs.someValue" />
    <x:someComponent>
        <span>#{foo}</span>
    </x:someComponent>
    

    another question 中查看更多信息。

    【讨论】:

    • 我一直在用这个。它有效,所以选择我自己的答案作为接受:)
    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2011-11-09
    相关资源
    最近更新 更多