Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 从Sitemesh迁移到Apache Tiles_Spring Mvc_Tiles_Spring Webflow_Tiles2_Apache Tiles - Fatal编程技术网

Spring mvc 从Sitemesh迁移到Apache Tiles

Spring mvc 从Sitemesh迁移到Apache Tiles,spring-mvc,tiles,spring-webflow,tiles2,apache-tiles,Spring Mvc,Tiles,Spring Webflow,Tiles2,Apache Tiles,我正在使用SpringMVC和SpringWebFlow开发自己的项目。在阅读了一些关于SpringWebflow和ajax的文章之后,我明白了更好的选择是使用ApacheTiles来呈现视图 在Sitemesh中,我使用了标记调用头()。模板中使用的标记允许在生成的HTML上呈现页面的整个head属性 有没有办法在Apache Tiles中实现这一点?根据我的阅读资料,我认为我必须做到以下几点: 两个JP,一个带有页面主体,另一个带有页眉定义。下面是一个模板、页面和tiles定义的示例,以便于

我正在使用SpringMVC和SpringWebFlow开发自己的项目。在阅读了一些关于SpringWebflow和ajax的文章之后,我明白了更好的选择是使用ApacheTiles来呈现视图

在Sitemesh中,我使用了标记调用头()。模板中使用的标记允许在生成的HTML上呈现页面的整个head属性

有没有办法在Apache Tiles中实现这一点?根据我的阅读资料,我认为我必须做到以下几点:

两个JP,一个带有页面主体,另一个带有页眉定义。下面是一个模板、页面和tiles定义的示例,以便于更好地理解

瓷砖定义

<tiles-definitions>
  <definition name="base" template="/WEB-INF/view/templates/tileslayout.jsp">
    <put-attribute name="title" value="Held - main page"/>
    <put-attribute name="body" value=""/>
    <put-attribute name="head" value=""/>
  </definition>

  <definition name="company.edit" extends="base">
    <put-attribute name="head" value="/WEB-INF/view/company/editHeader.jsp"></put-attribute>
    <put-attribute name="body" value="/WEB-INF/view/company/edit.jsp"></put-attribute>
  </definition>

</tiles-definitions>

模板:

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> 
<html>
<head>
 -- css and scripts --
 <tiles:insertAttribute name="head"  ignore="true"/>
<!--  <decorator:head /> -->
</head>

<body>

--- menu definition ---

<div class="container-fluid">
    <tiles:insertAttribute name="body"/>
<!--   <decorator:body/> -->
</div>
<hr/>      
<footer>
    -----
</footer>

</body>
</html>

--css和脚本--
---菜单定义---

-----
公司网页

<div class="container">
-- the page html code
</div>
<meta name="menu" content="company" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
.error {
    color: red;
}
</style>
<script type="text/javascript">
    $(document).ready(function() {
        $('#name').focus();
    });
</script>

--页面的html代码
总公司页面

<div class="container">
-- the page html code
</div>
<meta name="menu" content="company" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
.error {
    color: red;
}
</style>
<script type="text/javascript">
    $(document).ready(function() {
        $('#name').focus();
    });
</script>

.错误{
颜色:红色;
}
$(文档).ready(函数(){
$('#name').focus();
});
有时头部可能更复杂

生成的html是正常的。但我不想为简单的事情定义两个JP

我做错了什么


有更好的方法吗?

你的方法是正确的。Sitemesh使用的装饰图案可以解决这一问题,而Tiles使用的构图则不能。然而,我不会说这是一个很大的担忧

组合是概念上更简单的策略,资源密集度更低。很好,您正在学习这两种系统,它们不是相互排斥的,可以相互补充

Tiles是将页面分解为Tiles。您所拥有的与当前允许的一样好。你已经发现,在头部有一个重新出现的脚本,因此你把它分成了一块。虽然这并不像你所建议的那样简单,但是如果你把所有的站点功能放在一个脚本文件中,加载它会花费很短的时间,但是这样做之后就不会因为缓存而产生开销

如果安全性是一个问题(即应用程序中有不同的安全级别,并且不想通过公开其JS泄露高级用户的能力),那么您可以使用tiles属性来定义要引入哪些tiles。为此,请使用tiles版本2.2.2并使用tiles侦听器“org.apache.tiles.extras.complete.CompleteAutoloadTilesListener”,这将允许在tiles定义中使用通配符、EL、OGNL和MVEL。以下内容将显示wldcards如何大大减少定义的大小:

您的第二个定义“company.edit”如果您有多个公司,并且有多个动词,那么您可以编写以下定义:

<definition name="*.*" extends="base">
  <put-attribute name="head" value="/WEB-INF/view/{1}/{2}Header.jsp"></put-attribute>
  <put-attribute name="body" value="/WEB-INF/view/{1}/{2}.jsp"></put-attribute>
</definition>

现在,您只需在/WEB-INF/view/以及editHeader、viewHeader等下创建一个又一个公司

如果您升级到2.2.2并使用“org.apache.tiles.extras.complete.CompleteAutoloadTilesListener”,因为您需要编写多种解释表达式的方法:

<definition name="WILDCARD:*.*" extends="base">
  <put-attribute name="head" value="/WEB-INF/view/{1}/{2}Header.jsp"></put-attribute>
  <put-attribute name="body" value="/WEB-INF/view/{1}/{2}.jsp"></put-attribute>
</definition>

如果您决定将特定安全级别的所有JS放在一个磁贴中,您可能会说:

<put-attribute name="head" value="/WEB-INF/view/{1}/OGNL:'session.securityLevel'+'.jsp'"></put-attribute>

OGNL是默认的Struts2表达式语言,在您的情况下,您应该使用适当的EL或MVEL