JSF 1.2:ui:包含参数

时间:2011-03-13 17:43:59

标签: jsf parameters include reusability

让JSF 1.2两页(one.xhtml和other.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> 
...

到目前为止one.xhtmlother.xhtml的区别仅在于操作参数:

one.xhtml:<h:commandLink action="actionOne">
other.xhtml:<h:commandLink action="actionTwo">

是否可以使用一些通用的xhtml?
而不是one.xhtml和other.xhtml,这样的东西:

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

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

谢谢你的帮助。

2 个答案:

答案 0 :(得分:56)

您需要在<ui:param>内嵌套<ui:include>以将参数传递给所包含的文件。

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

并在include:

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

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

答案 1 :(得分:21)

除了BalusC的回答:

  

请注意,这仅支持字符串,   不是行动方法。对于后者你   需要升级到JSF 2.0和   使用复合组件。

有一种方法可以用JSF 1.2做到这一点,虽然它有点难看:

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

<h:commandButton action="#{actionBean[actionMethod]}" />
相关问题