java - 如何使用 Tiles 进行类似 Facelets 的模板合成?

标签 java spring jsp tiles

我正在使用 Spring、JSP 和 Tiles 做一个 Java Web 项目。在我们的上一个项目中,我们使用了 Facelets <ui:composition><ui:define>标签以在模板的 header 中包含 JS 和 CSS 库。我想知道是否有办法使用 Tiles 来做同样的事情。

这是我想要做的 Facelets 主模板的示例:

<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:sec="http://www.springframework.org/security/facelets/tags">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
        <title><ui:insert name="title">MediMercado</ui:insert></title>
        <link href="${request.contextPath}/css/layout.css" rel="stylesheet" type="text/css" />
        <ui:insert name="additional-js"></ui:insert>
    </head>
    <body>
         <ui:insert name="content">
             <ui:include src="main-content.xhtml"/>
         </ui:insert>
    </body>
</html>

页面模板:

<ui:composition template="/layout/layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:define name="additional-js">
        <script src="${request.contextPath}/js/jquery.js" type="text/javascript"></script>
    </ui:define>
    <ui:define name="content">
        <h1>Just an example</h1>
    </ui:define>
</ui:composition>

因此,在此示例中,页面模板中的 jquery 库包含在主模板的 HTML 头部中。

我们如何使用 Tiles 来做到这一点?

最佳答案

Tiles Tutorial涵盖这个主题。

(提示:在 Tiles 中,文件比在 JSF 中更加分离)

关于java - 如何使用 Tiles 进行类似 Facelets 的模板合成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5943424/

相关文章:

java - 将 Hibernate Query.list() 转换为 List<Type> 的 "proper"方法是什么?

java - Spring 批处理 : Tasklet with multi threaded executor has very bad performances related to Throttling algorithm

java - Spring 面 错误面 :flow-builder-services

java - 关于 Spring MVC 与 bootstrap 的问题

javascript - 无法发送带有 # in 参数的 Ajax 请求

Java:显示从另一个类中的方法创建的数组

java - 从另一个线程控制倒计时

jsp - 使用 <jsp :include> tag 将参数传递到另一个 JSP 文件

jsp - 将用户从 jsp 传递到 servlet

java - 使用标记解析表达式