【问题标题】:pass method through ui:include to custom component通过 ui:include 传递方法到自定义组件
【发布时间】:2017-09-01 15:17:25
【问题描述】:

我有 3 个文件:

ma​​in.xhtml

<ui:include src="included.xhtml">
    <ui:param name="bean" value="#{invoices}" />
    <ui:param name="method" value="initExchange" />
</ui:include>

included.xhtml

<s:compositeComponent bean="#{bean}" beanMethod="#{method}"
                    buttonActionListener="#{bean[method]()}" />

compositeComponent.xhtml

<cc:interface>
    <cc:attribute name="bean" />
    <cc:attribute name="beanMethod" />
    <cc:attribute name="buttonActionListener" method-signature="void f()" />
</cc:interface>
<cc:implementation>
    <h:outputText value="#{cc.attrs.bean}" />
    <h:outputText value="#{cc.attrs.beanMethod}" />
    <p:commandButton actionListener="#{cc.attrs.buttonActionListener}" />

h:outputTexts 没问题。但是点击按钮会出现异常:

目标不可达,标识符“bean”解析为空

如何将方法传递给按钮的actionListener?

【问题讨论】:

    标签: jsf-2 facelets composite-component


    【解决方案1】:

    当复合组件中的 actionListener 像 include.xhtml 一样写成 bean[method] 时有效:

    <p:commandButton actionListener="#{cc.attrs.bean[cc.attrs.beanMethod]}" />
    

    因此,通常通过多个阶段传递方法属性应始终由单独的 bean 和方法完成,而不是一个带有“方法签名”的属性。

    【讨论】:

      猜你喜欢
      • 2019-09-17
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2016-12-03
      • 2011-11-12
      • 1970-01-01
      相关资源
      最近更新 更多