动态ui包含和commandButton [英] Dynamic ui include and commandButton
问题描述
我有一个页面,其中包含动态来自另一个页面的内容(这是通过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>
这将重定向到<ui:composition>
中具有commandButton的secondPage.
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.
任何帮助将不胜感激.
推荐答案
您不能通过<ui:param>
传递方法表达式.它们被解释为值表达.
You can't pass method expressions via <ui:param>
. They're interpreted as value expression.
您基本上有3个选择:
-
通过2个参数分割bean实例和方法名称:
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 具有 <o:methodParam>
可以做到这一点.在标记文件中按以下方式使用它:
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" />
改为使用复合组件.您可以使用<cc:attribute method-signature>
将操作方法定义为属性.
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包含和commandButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!