【问题标题】:Preserve indents of inserted elements in Apache Tiles layout?在 Apache Tiles 布局中保留插入元素的缩进?
【发布时间】:2011-08-08 23:22:16
【问题描述】:

所以我有一个 Tiles 布局,其中包含一些属性。看起来是这样的:

<body>
    <div id="header">
        <tiles:insertAttribute name="header" />
    </div>
    <div id="content">
        <tiles:insertAttribute name="content" />
    </div>
    <div id="footer">
        <tiles:insertAttribute name="footer" />
    </div>
</body>

我的头元素文件如下所示:

<h1>Header</h1>
<div id="nav">
    <ul>
        <li>Nav Item 1</li>
        <li>Nav Item 2</li>
    </ul>
    <hr />
</div>

让我恼火的是,标题元素的缩进没有得到尊重。标头的渲染输出如下所示:

<body>
    <div id="header"> 
        <h1>Header</h1> 
<div id="nav"> 
    <ul> 
        <li>Nav Item 1</li> 
        <li>Nav Item 2</li> 
        </ul> 
    <hr /> 
</div>
</div>
....

我希望它看起来像这样:

<body>
    <div id="header"> 
        <h1>Header</h1> 
        <div id="nav"> 
            <ul> 
                <li>Nav Item 1</li> 
                <li>Nav Item 2</li> 
            </ul> 
            <hr /> 
        </div>
    </div>
    ....

有没有办法配置 Tiles 或添加某种过滤器来保留最终渲染输出中的缩进?最后,我目前正在修剪空格:

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
</jsp-config>

【问题讨论】:

    标签: java templates whitespace tiles taglib


    【解决方案1】:

    我不知道如何配置图块以保留缩进,但制作一个 servlet 过滤器在将响应 html 发送到浏览器之前对其进行清理并不难。网上可能已经有很多可用的了——我通过快速搜索找到的一个是JTidy filter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 2012-08-02
      • 2010-09-24
      • 1970-01-01
      • 2012-04-08
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多