Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 如何使用ui:包含参数?_Jsf_Parameters_Include_Reusability - Fatal编程技术网

Jsf 如何使用ui:包含参数?

Jsf 如何使用ui:包含参数?,jsf,parameters,include,reusability,Jsf,Parameters,Include,Reusability,有JSF 1.2两个页面(一个.xhtml和另一个.xhtml),根据以下规则包含到当前页面中: ... <c:if test="#{flowScope.Bean.param1}"> <ui:include src="one.xhtml"/> </c:if> <c:if test="#{!flowScope.Bean.param1}"> <ui:include src="other.

有JSF 1.2两个页面(一个.xhtml和另一个.xhtml),
根据以下规则包含到当前页面中:

...
    <c:if test="#{flowScope.Bean.param1}">
        <ui:include src="one.xhtml"/>
    </c:if> 

    <c:if test="#{!flowScope.Bean.param1}">
        <ui:include src="other.xhtml"/>
    </c:if> 
...
谢谢您的帮助。

您需要将
嵌套在
中,以便将参数传递到包含的文件中

<ui:include src="general.xhtml">
    <ui:param name="action" value="actionOne" />
</ui:include>

其中包括:

<h:commandButton action="#{action}" />


请注意,这只支持字符串,不支持操作方法。对于后者,您需要升级到JSF 2.0并使用。

除了BalusC的答案之外:

注意,这只支持字符串, 而不是行动方法。为了后者你 需要升级到JSF2.0和 使用复合组件

JSF1.2有一种方法可以做到这一点,尽管它有点难看:

<ui:include src="general.xhtml">
    <ui:param name="actionBean" value="#{myBackingBean}" />
    <ui:param name="actionMethod" value="edit" />
</ui:include>



谢谢,我知道cc,它们很棒,但在当前的jsf 1.2项目中无法使用它们。我将尝试您的解决方案并写回结果。它将根据您在问题中提出的方式工作。但是如果您使用的是
{bean.doSomething}
而不是
actionOne
,那么您确实需要获取JSF 2.0复合组件。请注意,param除了字符串之外还可以处理整个对象。@Adam:使用
时,是的。这不是秘密。但这不适用于总是转换为字符串的
。也许你最初的困惑就是基于此。@BalusC:我只是想详细说明一下,以备将来参考。感谢您在
f:param
上的注释及其与
ui:param
的比较。我从来没有使用过
f
library版本,我会记住它们的区别。我可以知道为什么actionBean的值需要用#{}来包围它才能工作吗?
<ui:include src="general.xhtml">
    <ui:param name="actionBean" value="#{myBackingBean}" />
    <ui:param name="actionMethod" value="edit" />
</ui:include>
<h:commandButton action="#{actionBean[actionMethod]}" />