使用 ui:composition 时如何更改页面的头元素

发布于 2024-12-21 06:09:01 字数 2246 浏览 2 评论 0原文

我想问一个问题,我有一个像这样的主模板

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>Login</title>
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include src="header.xhtml" id="header"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content"></ui:insert>
            </div>
        </div>
        <div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
            <ui:insert name="bottom">
                <ui:include src="footer.xhtml" id="footer"/>
            </ui:insert>
        </div>
    </h:body>
</html>

在我的每个页面上我都使用类似的东西

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>City Setup</title>
    </h:head>

    <h:body>
        <ui:composition template="./WEB-INF/templates/layout.xhtml">
            <ui:define name="content">
                <h:form id="cityReviewform">
                    ......
                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</html>

现在由于 ui;composition 发生了什么,我的图块属性现在在每个页面上工作,因为 ui:composition 丢弃它之外的每个标签。现在在每个页面上我都有一个登录标题(即主模板)。所以我想问我怎样才能在每个页面上显示自己的标题而不是登录(主模板标题)?

谢谢

I want to ask a question that i have a master template like this

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>Login</title>
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include src="header.xhtml" id="header"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content"></ui:insert>
            </div>
        </div>
        <div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
            <ui:insert name="bottom">
                <ui:include src="footer.xhtml" id="footer"/>
            </ui:insert>
        </div>
    </h:body>
</html>

On my each page i am using something like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>City Setup</title>
    </h:head>

    <h:body>
        <ui:composition template="./WEB-INF/templates/layout.xhtml">
            <ui:define name="content">
                <h:form id="cityReviewform">
                    ......
                </h:form>

            </ui:define>
        </ui:composition>
    </h:body>
</html>

Now what is happening that because of the ui;composition my tile attribute is now working on each page, because ui:composition discard every tag outside of it. Now on each page i have a title of Login(i.e of master template). So i want to ask that how can i do this that on each page, its own title shown instead of Login(master tempalte title)?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱&纷飞 2024-12-28 06:09:01

在模板客户端中, 之外的一切都会被忽略。您需要更改模板方法,为主模板中的标题提供 ,以便可以通过 定义它。 code> 在模板客户端中。

主模板:

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

    <h:head>
        <title><ui:insert name="title">Login</ui:insert></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include id="header" src="header.xhtml"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content" />
            </div>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">
                <ui:include id="footer" src="footer.xhtml" />
            </ui:insert>
        </div>
    </h:body>
</html>

模板客户端:

<ui:composition template="/WEB-INF/templates/layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="title">City Setup</ui:define>

    <ui:define name="content">
        <h:form id="cityReviewform">
            ...
        </h:form>
    </ui:define>
</ui:composition>

另请参阅:

In the template client, everything outside <ui:composition> is ignored. You need to change your template approach to provide an <ui:insert> for the title in the master template, so that it can be defined by an <ui:define> in the template client.

Master template:

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

    <h:head>
        <title><ui:insert name="title">Login</ui:insert></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">
                <ui:include id="header" src="header.xhtml"/>
            </ui:insert>
        </div>
        <div>
            <div id="content">
                <ui:insert name="content" />
            </div>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">
                <ui:include id="footer" src="footer.xhtml" />
            </ui:insert>
        </div>
    </h:body>
</html>

Template client:

<ui:composition template="/WEB-INF/templates/layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="title">City Setup</ui:define>

    <ui:define name="content">
        <h:form id="cityReviewform">
            ...
        </h:form>
    </ui:define>
</ui:composition>

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文