我有两个 xhtml 文件,一个包含另一个。我已经知道如何将控制器和要调用的方法传递给对话框,我不确定是否可能,是将参数/对象实际传递给将被调用的方法。我尝试了类似的方法,但是 Eclipse 告诉我这部分有语法错误
actionListener="#{bean[confMethod(param1, param2)]}"
但它没有任何问题
actionListener="#{bean[confMethod]}"
文件1.xhtml:
<ui:composition>
.....
<ui:include src="/jsf/include/dg_confirm.xhtml">
<ui:param name="bean" value="#{myController}" />
<ui:param name="question" value="Are you sure?" />
<ui:param name="confMethod" value="myMethod" />
<ui:param name="param1" value="#{otherController.param1}" />
<ui:param name="param2" value="#{urlToFollow}" />
</ui:include>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
和对话框
dg_confirm.xhtml
....
<p:commandButton value="Yes" oncomplete="PF('dlg_conf').hide();" actionListener="#{bean[confMethod(param1, param2)]}" ajax="false"/>
.....
Run Code Online (Sandbox Code Playgroud)
问题:是否可以在 JSF 中以某种方式传递方法的参数?
actionListener="#{bean[confMethod(param1, param2)]}"
Run Code Online (Sandbox Code Playgroud)
这个语法确实是无效的。您基本上期望这confMethod是一个静态函数,它根据给定的两个参数返回动态方法的名称。
正确的语法如下:
actionListener="#{bean[confMethod](param1, param2)}"
Run Code Online (Sandbox Code Playgroud)