动态 ui 包含和命令按钮 [英] Dynamic ui include and commandButton

查看:16
本文介绍了动态 ui 包含和命令按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a page which includes content from another page dynamically (this is done by a method in the bean)

firstPage.xhtml

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

这会重定向到 中的 secondPage,其中包含 commandButton.

This redirects to a secondPage which is within <ui:composition> which has commandButton.

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 不起作用.

The commandButton in the secondPage.xhtml is not working.

任何帮助将不胜感激.

推荐答案

你不能通过 传递方法表达式.它们被解释为值表达式.

You can't pass method expressions via <ui:param>. They're interpreted as value expression.

您基本上有 3 个选择:

You've basically 3 options:

  1. 将 bean 实例和方法名称拆分为 2 个参数:

  1. Split the bean instance and the method name over 2 parameters:

<ui:param name="bean" value="#{managedBean}" />
<ui:param name="method" value="someAction" />

并使用大括号符号[]将它们耦合到标记文件中,如下所示:

And couple them in the tag file using brace notation [] as follows:

<p:commandButton action="#{bean[method]}" value="Submit" />


  • 创建一个将值表达式转换为方法表达式的标记处理程序.JSF 实用程序库 OmniFaces 有一个 就是这样做的.在标签文件中使用如下:


  • Create a tag handler which converts a value expression to a method expression. The JSF utility library OmniFaces has a <o:methodParam> which does that. Use it as follows in the tag file:

    <o:methodParam name="action" value="#{method}" />
    <p:commandButton action="#{action}" value="Submit" />
    


  • 改用复合组件.您可以使用 将操作方法​​定义为属性.


  • Use a composite component instead. You can use <cc:attribute method-signature> to define action methods as attributes.

    <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}" />
    

  • 这篇关于动态 ui 包含和命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆