gpt4 book ai didi

jsf-2 - 动态 ui 包含和 commandButton

转载 作者:行者123 更新时间:2023-12-03 22:20:23 24 4
gpt4 key购买 nike

我有一个页面,其中包含来自另一个页面的动态内容(这是通过 bean 中的方法完成的)

firstPage.xhtml

<ui:include src="#{managedBean.pageView}">
<ui:param name="method" value="#{managedBean.someAction}"/>
</ui:include>

这将重定向到位于 <ui:composition> 内的第二页其中有命令按钮。

secondPage.xhtml
<ui:composition>
..
..
<p:commandButton actionListener=#{method} value="Submit"/>
</ui:composition>

ManagedBean
public String pageView(){
return "secondPage.xhtml";
}

public void someAction(){
*someAction*
}

secondPage.xhtml 中的 commandButton 不起作用。

任何帮助将不胜感激。

最佳答案

你不能通过 <ui:param> 传递方法表达式.它们被解释为值表达。

您基本上有 3 个选择:

  • 将 bean 实例和方法名称拆分为 2 个参数:
    <ui:param name="bean" value="#{managedBean}" />
    <ui:param name="method" value="someAction" />

    并使用大括号表示法将它们耦合到标记文件中 []如下:
    <p:commandButton action="#{bean[method]}" value="Submit" />

  • 创建一个将值表达式转换为方法表达式的标记处理程序。 JSF 实用程序库 OmniFaces有一个 <o:methodParam> 这样做。在标签文件中使用如下:
    <o:methodParam name="action" value="#{method}" />
    <p:commandButton action="#{action}" value="Submit" />

  • 使用 composite component反而。您可以使用 <cc:attribute method-signature>将操作方法​​定义为属性。
    <cc:interface>
    <cc:attribute name="method" method-signature="void method()"/>
    </cc:interface>
    <cc:implementation>
    <p:commandButton action="#{cc.attrs.method}" value="Submit"/>
    </cc:implementation>

    用法如下:
    <my:button method="#{managedBean.someAction}" />
  • 关于jsf-2 - 动态 ui 包含和 commandButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15002272/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com