Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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
Templates 测试是否在模板客户端中定义了ui:insert_Templates_Jsf 2_Facelets - Fatal编程技术网

Templates 测试是否在模板客户端中定义了ui:insert

Templates 测试是否在模板客户端中定义了ui:insert,templates,jsf-2,facelets,Templates,Jsf 2,Facelets,我想知道是否有可能知道ui:insert是在ui:composition中定义的。 我知道我可以使用单独的ui:param,但我只是想不使用它,以保持它的简单性和不易出错 示例: 模板 。。。 ... 第1页 。。。 边栏内容 页面内容 ... 第2页 。。。 页面内容 ... ui:param对我来说是最好的选择。这只是正确使用它的问题。作为一个简单的例子,我在这里定义了一个参数来指定是否有侧边栏。请记住,您可以在模板中定义默认插入定义,因此只需在其中声明: template.xhtml

我想知道是否有可能知道
ui:insert
是在
ui:composition
中定义的。 我知道我可以使用单独的
ui:param
,但我只是想不使用它,以保持它的简单性和不易出错

示例:

模板

。。。
...
第1页

。。。
边栏内容
页面内容
...
第2页

。。。
页面内容
...

ui:param
对我来说是最好的选择。这只是正确使用它的问题。作为一个简单的例子,我在这里定义了一个参数来指定是否有侧边栏。请记住,您可以在模板中定义默认插入定义,因此只需在其中声明:

template.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:insert name="sidebar">
        <!-- By default, there's no sidebar, so the param will be present.
            When you replace this section for a sidebar in the client template,
            the param will  be removed from the view -->
        <ui:param name="noSideBar" value="true" />
    </ui:insert>

    <div class="#{noSideBar ? 'style1' : 'style2'}">
        <ui:insert name="content" />
    </div>

</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="sidebar" />
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
page2.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:insert name="sidebar">
        <!-- By default, there's no sidebar, so the param will be present.
            When you replace this section for a sidebar in the client template,
            the param will  be removed from the view -->
        <ui:param name="noSideBar" value="true" />
    </ui:insert>

    <div class="#{noSideBar ? 'style1' : 'style2'}">
        <ui:insert name="content" />
    </div>

</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="sidebar" />
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>

没有定义侧边栏#{noSideBar}

这样,您只需担心是否在客户端视图中包含边栏。

ui:param
对我来说是最好的方法。这只是正确使用它的问题。作为一个简单的例子,我在这里定义了一个参数来指定是否有侧边栏。请记住,您可以在模板中定义默认插入定义,因此只需在其中声明:

template.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:insert name="sidebar">
        <!-- By default, there's no sidebar, so the param will be present.
            When you replace this section for a sidebar in the client template,
            the param will  be removed from the view -->
        <ui:param name="noSideBar" value="true" />
    </ui:insert>

    <div class="#{noSideBar ? 'style1' : 'style2'}">
        <ui:insert name="content" />
    </div>

</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="sidebar" />
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
page2.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:insert name="sidebar">
        <!-- By default, there's no sidebar, so the param will be present.
            When you replace this section for a sidebar in the client template,
            the param will  be removed from the view -->
        <ui:param name="noSideBar" value="true" />
    </ui:insert>

    <div class="#{noSideBar ? 'style1' : 'style2'}">
        <ui:insert name="content" />
    </div>

</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="/template.xhtml">
    <ui:define name="sidebar" />
    <ui:define name="content">
        No sidebar defined? #{noSideBar}
    </ui:define>
</ui:composition>

没有定义侧边栏#{noSideBar}

这样,您只需担心是否在客户端视图中包含侧边栏。

谢谢,我从来没有想过这样做,我很快就会尝试!谢谢你,我从来没有想过那样做,我很快就会试试的!