Как удалить плитку в плитках Apache для определенного вида?
Я хочу знать, как удалить плитку из вида. Мой основной вид выглядит так
Конфигурация плитки состоит из 4 частей: заголовок, меню, тело и нижний колонтитул.
Теперь я знаю, что если я запрашиваю новую страницу, я могу переопределить основной вид, например, чтобы заменить тело, чтобы там отображался другой контент.
Но я хочу иметь возможность, если я нажму на ссылку в меню, которая приведет меня к странице, которая имеет только заголовок и тело (без меню или нижнего колонтитула).
Затем пользователь завершит работу с мастером, с помощью которого он сможет перейти с одной страницы на другую, а затем, как только он это сделает, он должен снова вернуться к основному макету.
И это мой вопрос: как убрать меню и нижний колонтитул из вида? Мой вопрос останавливается здесь.
Поскольку я не могу найти много документации по плиткам, я подумал, что хотел бы включить пошаговый пример для кого-то еще, кто пытается получить рабочий пример использования Apache Tiles и Spring MVC с использованием Spring Tool Suite (моя версия СТС 3.2.0).
ШАГИ Следовать, чтобы создать простой сайт с использованием STSСоздать новый проект STS
Файл >> Создать >> Spring Template Project >> Spring MVC Project
Выберите опцию «Spring MVC Project»
Дайте вашему проекту имя и пакет верхнего уровня
Это создаст проект, похожий на ниже
Измените POM для использования SPRING 3.2.0.RELEASEИз:
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
Для того, чтобы:
<org.springframework-version>3.2.0.RELEASE</org.springframework-version>
Добавьте следующие зависимости в файл POM, чтобы включить зависимости Apache Tile<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-template</artifactId>
<version>3.0.1</version>
</dependency>
Измените «servlet-context.xml», чтобы использовать TilesViewResolver вместо стандартного InternalViewResolver<!-- Remove -->
<beans:bean class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></beans:property>
<beans:property name="order" value="0"></beans:property>
</beans:bean>
<!-- Add -->
<beans:bean class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></beans:property>
<beans:property name="order" value="0"></beans:property>
</beans:bean>
Добавьте ссылку, чтобы узнать, где настроены плитки<beans:bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" id="tilesConfigurer">
<beans:property name="definitions" value="/WEB-INF/spring/tiles.xml"> </beans:property>
</beans:bean>
Теперь укажите представление - файлы JSP, которые будут использоваться для указания представлений… например, верхний колонтитул, меню, нижний колонтитул и тело (это может быть фактический контент, и обычно у вас будет более 1 тела в зависимости от того, что пользователь нажал в меню) - макет будет похож на самое первое изображение в этом посте.Файлы JSP, созданные в папке просмотра, в каждом из которых есть содержимое
header.jsp
<h2>This is the header</h2>
footer.jsp
<p>This is the footer</p>
content1.jsp
<h1>This is content page 1</h1>
<p>Blah blah content 1</p>
content2.jsp
<h1>This is content page 2</h1>
<p>Blah blah content 2</p>
menu.jsp
<h2>Menu</h2>
<a href="">Go to home page</a><br/>
<a href="page1">Display page 1</a><br/>
<a href="page2">Display page 2</a>
Когда проект создается, он создает контроллер по умолчанию под названием «HomeController.java». Это то, что используется, чтобы определить, куда идти дальше при нажатии на пункты меню. Если вы откроете домашний контроллер и измените его на следующийpackage com.stp.myapp;
import java.util.Locale;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
/**
* The request mapping has a value. That is what we are
* requesting for. When opening the site it will request the main
* page or the index page. The “/” indicates it is the index page.
* In this simple example we simply return the new ModalAndView with
* the page in the view folder. In This case it is the mainPage.
* The mainPage is the reference of what is configured in the
* apache tiles configuration – not the actual page that will be
* displayed.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView home(Locale locale, Model model) {
return new ModelAndView("mainPage");
}
/**
* The request mapping is for page1 (page1 is the value from the menu.
*/
@RequestMapping(value = "/page1", method = RequestMethod.GET)
public ModelAndView viewArticle(Locale locale, Model model) {
return new ModelAndView("displayPageContent1");
}
@RequestMapping(value = "/page2", method = RequestMethod.GET)
public ModelAndView viewEmployees(Locale locale, Model model) {
return new ModelAndView("displayPageContent2");
}
}
Теперь давайте настроим плиткиСоздайте файл «iles.xml »с
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<!-- This file has several definitions of page layouts -->
<tiles-definitions>
<!-- The main definition with the header footer menu and body -->
<definition name="base.definition" template="/WEB-INF/views/mainTemplate.jsp">
<put-attribute name="title" value=""></put-attribute>
<put-attribute name="header" value="/WEB-INF/views/header.jsp"></put-attribute>
<put-attribute name="menu" value="/WEB-INF/views/menu.jsp"></put-attribute>
<put-attribute name="body" value=""></put-attribute>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"></put-attribute>
</definition>
<!-- Now you can specify as many layours as you want... The name will match the names the -->
<!-- HomeController.java returns aka... as we specified it as displayPageContent1 and displayPageContent2 -->
<!-- You can override each of the base.definition entries. In this we change the page title and display a different -->
<!-- page as the body. As we didn't override the menu of footer it will display as specified in tha base.defition-->
<definition name="displayPageContent1" extends="base.definition">
<put-attribute name="title" value="Page context 1 displaying..."></put-attribute>
<put-attribute name="body" value="/WEB-INF/views/content1.jsp"></put-attribute>
</definition>
<definition name="displayPageContent2" extends="base.definition">
<put-attribute name="title" value="Employees List"></put-attribute>
<put-attribute name="body" value="/WEB-INF/views/content2.jsp"></put-attribute>
</definition>
<definition name="mainPage" extends="base.definition">
<put-attribute name="title" value="This is the home page being displayed....."></put-attribute>
<put-attribute name="body" value="/WEB-INF/views/home.jsp"></put-attribute>
</definition>
</tiles-definitions>
Файл tile.xml имеет «mainTemplate.jsp», определенный как базовое определение. Создайте файл «mainTemplate.jsp», который имеет основной HTML-макет. В файлах есть «tile: insertAttribute», которое определяет части базовой компоновки, которые могут быть переопределены в каждом представлении.
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!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=UTF-8">
<title>
<tiles:insertAttribute name="title" ignore="true"></tiles:insertAttribute>
</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" align="left">
<tr>
<td colspan="2" align="center">
<tiles:insertAttribute name="header"></tiles:insertAttribute>
</td>
</tr>
<tr>
<td>
<tiles:insertAttribute name="menu"></tiles:insertAttribute>
</td>
<td>
<tiles:insertAttribute name="body"></tiles:insertAttribute>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<tiles:insertAttribute name="footer"></tiles:insertAttribute>
</td>
</tr>
</table>
</body>
</html>
В конце вы должны получить файловую структуру, похожую на эту