当使用< ui:composition>模板,我应该在哪里声明< f:metadata&gt ;? [英] When using <ui:composition> templating, where should I declare the <f:metadata>?

查看:110
本文介绍了当使用< ui:composition>模板,我应该在哪里声明< f:metadata&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将我的JSF应用程序转换为可标记页面的过程中,我已经取得了很大的进步,但是我想知道我是否以正确的方式来做.一个问题是 f:metadata 标签是否存在最佳实践位置?

I have made a lot of progress in converting my JSF applications to book-markable pages, but I am wondering if I am doing it the right way. One question is that is there a best-practice location for the f:metadata tags?

我典型的Facelets客户端页面如下:

My typical Facelets client page looks like this:

    <ui:composition template="./pattern.xhtml">

        <ui:define name="content">

            <f:metadata>
                <f:viewParam name="userId" value="#{bean.userId}" />
                <f:viewParam name="startRecord" value="#{bean.startRecord}" />
                <f:viewParam name="pageSize" value="#{bean.pageSize}" />
                <f:viewParam name="sort" value="#{bean.sort}" />
            </f:metadata>

            <h1>Data Table</h1>

etc

因此,在我的页面正文中遇到了 f:metadata 和子 f:viewParam 标记.我的 pattern.xhtml 模板还具有一个部分(名为标头"),可以将这些标签放在标头部分中.应该把它们放在那里吗?会有所不同吗?还是我准备进行一些尚未见到的副作用?

So the f:metadata and child f:viewParam tags are encountered in the body of my page. My pattern.xhtml template also has a section (named "header") that could put these tags in the header section. Should they be put there? Does it make a difference or am I set up for some side effect I haven't seen yet?

推荐答案

从技术上讲,只要在顶级视图中,在视图中的<f:metadata>声明位置就无关紧要(因此,在使用模板时,在模板客户端中,因此不在主模板中).构建视图时,元数据基本上不是JSF组件树的一部分,而是视图根的一部分(您可以通过

Technically, it doesn't matter where you declare the <f:metadata> in the view as long as it's in the top level view (so, when using templating, in the template client and thus not in the master template). When the view get built, the metadata is basically not part of the JSF component tree, but of the view root (which you can obtain on a per-view basis by ViewDeclarationLanguage#getViewMetadata()).

大多数自记录文档是将<f:metadata>放在视图顶部,以便您乍看即可看到任何元数据,而无需滚动到视图源代码的中途或底部.

Most self-documenting would be to put the <f:metadata> in the top of the view, so that you can see any metadata at first glance without the need to scroll to halfway or bottom the view source code.

使用普通页面时,只需将其放在<h:head>之前即可.

When using a plain page, just put it right before the <h:head>.

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
>
    <f:metadata>
        <f:viewParam name="userId" value="#{bean.userId}" />
        <f:viewParam name="startRecord" value="#{bean.startRecord}" />
        <f:viewParam name="pageSize" value="#{bean.pageSize}" />
        <f:viewParam name="sort" value="#{bean.sort}" />
    </f:metadata>

    <h:head>
        ...
    </h:head>

    <h:body>
        ...
    </h:body>
</html>

使用模板时,建议的方法如中所述<f:metadata>标记文档,将是在主模板中声明一个单独的<ui:insert name="metadata">,并让客户端在<ui:define name="metadata">中定义<f:metadata>.

When using templating, the recommended approach, as stated in the <f:metadata> tag documentation, would be to declare a separate <ui:insert name="metadata"> in the master template and let the client define the <f:metadata> in an <ui:define name="metadata">.

<ui:composition template="/WEB-INF/pattern.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
>
    <ui:define name="metadata">
        <f:metadata>
            <f:viewParam name="userId" value="#{bean.userId}" />
            <f:viewParam name="startRecord" value="#{bean.startRecord}" />
            <f:viewParam name="pageSize" value="#{bean.pageSize}" />
            <f:viewParam name="sort" value="#{bean.sort}" />
        </f:metadata>
    </ui:define>

    <ui:define name="content">
        <h1>Data Table</h1>
        ...
    </ui:define>
</ui:composition>

这篇关于当使用&lt; ui:composition&gt;模板,我应该在哪里声明&lt; f:metadata&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆