0
嗨,我用SpringMVC使用瓷磚,我有我的渲染頁面的頁眉部分包含動態生成的選擇框的問題沒有標題渲染。動態選擇框的內容使用Tiles2用時用SpringMVC
我有一個瓷磚的配置文件看起來像:
<!-- Default Main Template -->
<definition name=".mainTemplate" template="/WEB-INF/jsp/layout.jsp">
<put-attribute name="title" value="TouchPoint.com" type="string" />
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
<put-attribute name="body" value="/WEB-INF/jsp/blank.jsp" />
</definition>
<definition name="mySubscriptions" extends=".mainTemplate">
<put-attribute name="body" value="/WEB-INF/jsp/mySubscriptions.jsp" />
</definition>
<definition name="addSubscription" extends=".mainTemplate">
<put-attribute name="body" value="/WEB-INF/jsp/addSubscription.jsp" />
</definition>
的layout.jsp樣子:
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name='keywords' content="GoAd Ltd ...................." />
<meta name='description' content="GoAd Ltd..............................................." />
<link rel="stylesheet" type="text/css" href="resources/css/header.css" />
<link rel="stylesheet" type="text/css" href="resources/css/common.css" />
<link rel="stylesheet" type="text/css" href="resources/css/footer.css" />
<script language="javascript" type="text/javascript" src="/resources/js/common.js"></script>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
<table cellpadding="2" cellspacing="2" align="center">
<tr>
<td height="30"><tiles:insertAttribute name="header" /></td>
</tr>
<tr>
<td height="300" ><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td height="30"><tiles:insertAttribute name="footer" /></td>
</tr>
</table>
</body>
</html>
的header.jsp中的樣子:
<div class="header0">
<div style="overflow:hidden;">
<div class="header1">
<img src="resources/images/logo.jpg" style="padding:5px" alt="LOGO" />
</div>
<div class="header2">
<div class="header3">
<div class="header4">
<span class="header7">
<select name="topic" id="topicSelect" style="width:375px">
<c:forEach items="${topicList}" var="topic">
<option value="${topic.id}">${topic.name}</option>
</c:forEach>
</select>
</span>
<a class="button" href="#" onclick="this.blur(); return false;"><span>Search</span></a>
</div>
<div class="header5">
<a href="" class="nav" class="nav">Advanced Search</a>
</div>
</div>
<div>
<span class="header8"><a href="" class="nav">Home</a></span>
<span class="header8"><a href="" class="nav">Add Advertisement</a></span>
<span class="header8"><a href="" class="nav">Subscriptions /<br/>Advertisements</a></span>
<span class="header8"><a href="" class="nav">Your Profile</a></span>
</div>
</div>
<div class="header6">
<span class="header9"><a href="" class="nav">Create Account</a></span>
<span class="header9"> or </span>
<span class="header9"><a href="" class="nav">Sign In</a></span>
</div>
</div>
<div>
<hr class="horizontalRule"></hr>
</div>
</div>
而且我的控制器看起來像:
package com.touchpoint.controller;
import com.touchpoint.form.Topic;
import com.touchpoint.service.TopicService;
import java.util.Map;
import java.util.List;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TopicController {
@Autowired
private TopicService topicService;
@RequestMapping("/mySubscriptions")
public String listTopics(Map<String,Object> map){
map.put("topic", new Topic());
map.put("topicList", topicService.listTopic());
System.out.println("--------------------------------------------->Received request to show mySubscriptions page");
List<Topic> topics = topicService.listTopic();
for(Topic topic : topics) {
System.out.println("--------------------------------------------->topic: "+topic.getName());
}
return "mySubscriptions";
}
@RequestMapping("/addSubscription")
public String getAddSubscriptionPage(){
System.out.println("--------------------------------------------->Received request to show addSubscriptions page");
return "addSubscription";
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public String addTopic(@ModelAttribute("topic")Topic topic, BindingResult result){
topicService.addTopic(topic);
return "redirect:/index";
}
@RequestMapping("/delete/{topicId}")
public String deleteTopic(@PathVariable("topicId") Integer topicId){
topicService.removeTopic(topicId);
return "redirect:/index";
}
}
出於某種原因,我的選擇框爲空時,頁面呈現,雖然塊配置似乎工作!在我開始使用拼貼之前,我使用一個簡單的包含標籤來包含我的標題,如下所示:
這工作正常,我的選擇框填充在我的標題中。瓷磚已停止工作!有沒有人有任何想法爲什麼?
感謝,
肖恩