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 ApacheTiles:在运行时更改模板页面_Spring Mvc_Tiles - Fatal编程技术网

Spring mvc ApacheTiles:在运行时更改模板页面

Spring mvc ApacheTiles:在运行时更改模板页面,spring-mvc,tiles,Spring Mvc,Tiles,我有一个问题:假设在SpringMVC3.0环境中,我使用tile管理视图:我有一个包含所有视图定义的xml文件。每个视图都扩展一个特定的模板。我有两个模板:一个用于呈现completeDOM(),另一个用于partialDOM(…)。问题是,有一些视图可以在fullDOM和partialDOM中检索,但我不想编写两个类似的定义 我正在考虑一种动态方法:在运行时注入视图的模板,指定一个http参数,该参数应该包含模板的名称。如果请求包含该参数,则Tiles应覆盖由视图扩展的模板,并使用http参

我有一个问题:假设在SpringMVC3.0环境中,我使用tile管理视图:我有一个包含所有视图定义的xml文件。每个视图都扩展一个特定的模板。我有两个模板:一个用于呈现completeDOM(),另一个用于partialDOM(…)。问题是,有一些视图可以在fullDOM和partialDOM中检索,但我不想编写两个类似的定义

我正在考虑一种动态方法:在运行时注入视图的模板,指定一个http参数,该参数应该包含模板的名称。如果请求包含该参数,则Tiles应覆盖由视图扩展的模板,并使用http参数值检测到的模板


有什么建议吗

我认为视图准备人员可能会有所帮助:
我知道这是一个老问题,但我需要做这件事,所以我想我会分享我的解决方案

平铺允许他们称之为“”的内容,这允许您修改定义。因此,您可以重用现有定义,只需交换模板即可:

<tiles:insertDefinition name="existingDefinition" template="alternateTemplate.jsp" />

在spring TileConfiguration中,您需要设置可变容器:

<property name="useMutableTilesContainer" value="true"/>
<property name="checkRefresh" value="true"/>

在Spring控制器中:

ModelAndView model = new ModelAndView();
MutableTilesContainer container = (MutableTilesContainer)ServletUtil.getContainer(request.getSession().getServletContext());
Attribute attribute = new Attribute("your template jsp");
HashMap<String, Attribute>  attributes = new HashMap<String, Attribute>();
attributes.put("body", attribute);
Definition definition = new Definition("your definition name", "your jsp", attributes);
definition.setExtends("your definition template name");
definition = PatternUtil.replacePlaceholders(definition, "your definition name", new Object());
container.register(definition, request, response);
model.setViewName("your definition name");
ModelAndView model=newmodelandview();
MutableTileContainer容器=(MutableTileContainer)ServletUtil.getContainer(request.getSession().getServletContext());
属性=新属性(“您的模板jsp”);
HashMap attributes=新的HashMap();
属性。放置(“身体”,属性);
定义=新定义(“您的定义名称”、“您的jsp”、属性);
setExtends(“您的定义模板名称”);
definition=PatternUtil.replacep占位符(定义,“您的定义名称”,new Object());
容器。寄存器(定义、请求、响应);
model.setViewName(“您的定义名称”);