【问题标题】:Set Managed Bean as parameter in Composite Component将托管 Bean 设置为复合组件中的参数
【发布时间】:2011-12-30 22:15:35
【问题描述】:

有没有办法在复合组件中设置托管 bean 参数,然后让使用类来决定使用哪个实际托管 bean?

类似于:comp.xhtml

       <cc:interface>
            <cc:attribute name="price" />
            <cc:param name="pageBean" value="#{superBean}" />       
       <cc:interface>
       <cc:implementation>
                <h:outputText value="#{cc.attrs.price}"/>
       </cc:implementation>

然后,在使用页面中

   <ezcomp:comp pageBean="actualBean"
                          price="#{actualBean.price}" >

    </ezcomp:comp> 

在我的例子中,ActualBean 是 SuperBean 的子类型。

我什至不确定这是否可能,但如果有人证明我错了,那就太好了。

提前谢谢你

【问题讨论】:

  • 这毫无意义。功能需求究竟是什么?将托管 bean 类型限制为某种类型?
  • 基本上是删除重复代码。我有很多需要在复合组件中设置的属性。使用页面的唯一不同是托管 bean 的名称,它们都是超级 bean 的子类型。这不是必需的,我只是想知道这是否可能。

标签: jsf jsf-2 facelets composite-component managed-bean


【解决方案1】:

基本上是删除重复代码。我有很多需要在复合组件中设置的属性。使用页面的唯一不同是托管 bean 的名称,它们都是超级 bean 的子类型。

您不需要指定所有属性。仅指定 bean 就足够了。您可以直接在复合组件中引用它的属性。

<cc:interface>
    <cc:attribute name="pageBean" type="com.example.SuperBean" required="true" />       
<cc:interface>
<cc:implementation>
    <h:outputText value="#{cc.attrs.pageBean.price}"/>
</cc:implementation>

<ezcomp:comp pageBean="#{actualBean}" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    相关资源
    最近更新 更多