开发者

How to do Facelets-like template composition using Tiles?

开发者 https://www.devze.com 2023-03-04 07:13 出处:网络
I\'m doing a Java Web Project using Spring, JSP and Tiles. In our last project we have used Facelets <ui:composition> and <ui:define> tags to include JS and CSS libraries in the header of

I'm doing a Java Web Project using Spring, JSP and Tiles. In our last project we have used Facelets <ui:composition> and <ui:define> tags to include JS and CSS libraries in the header of a template. I'm wondering if there is a way to do the same using Tiles.

Here's an example of the Facelets master template what I'm trying to do:

<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>

Page template:

<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>

So in this example the jquery library in our page template is been included in the HTML head of the master template.

How can we do this using Tiles?


The Tiles Tutorial cover this theme.

(Hint: In Tiles the files are more separated than in JSF)

0

精彩评论

暂无评论...
验证码 换一张
取 消