Configuration Template jsp using Apache Tiles with Spring

Asked

Viewed 232 times

2

I did all of the configuration below, but the template structure I created using Tiles is not being presented on the main page along with your CSS. If anyone can help!

Tiles-config.xml

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
    <definition name="defaultTemplate" template="/WEB-INF/pages/model/dafault.jsp">
        <put-attribute name="titulo" value="SGR"/>
        <put-attribute name="header" value="/WEB-INF/pages/model/header.jsp"/>
        <put-attribute name="menu" value="/WEB-INF/pages/model/menu.jsp"/>
        <put-attribute name="body" value="" />

    </definition>

    <definition name="index"  extends="defaultTemplate" >
        <put-attribute name="body" value="/index.jsp"/>
    </definition>

    <definition name="principal" extends="defaultTemplate">
        <put-attribute name="body" value="/public/principal.jsp"/>
        <put-attribute name="titulo" value="Bem vindo(a)!"/>
    </definition>
</tiles-definitions>

application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <context:annotation-config />

    <context:component-scan base-package="com.pessoal.rsw" />

    <mvc:annotation-driven/>

    <mvc:default-servlet-handler />

    <mvc:resources mapping="/resources/**" location="/resources/"/>

    <mvc:view-controller path="/" view-name="index"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- O view resolver da aplicação -->
    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
    </bean>

    <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"/> -->

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles/tiles-config.xml</value>
            </list>
        </property>
    </bean>

</beans>

Template default.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><tiles:getAsString name="titulo"/></title>
    <link rel="stylesheet" href="<c:url value="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="../resources/css/bootstrap.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="../resources/css/bootstrap-theme.min.css"/>" />
    <link rel="stylesheet" href="<c:url value="../resources/fonts/font-awesome/css/font-awesome.min.css"/>"/>
    <link rel="stylesheet" href="<c:url value="../resources/css/custom.css"/>" />

    <script type="text/javascript" src="<c:url value="../resources/js/jquery-1.11.1.min.js"/>"></script>
    <script type="text/javascript" src="<c:url value="../resources/js/bootstrap.min.js"/>"></script>
</head>
<body>

    <div class="container">

        <!-- Header -->

        <tiles:insertAttribute name="header" />

        <!-- Menu Page -->

        <div>   
            <tiles:insertAttribute name="menu" />
        </div>

        <!-- Body Page -->

        <div>
            <tiles:insertAttribute name="body" />
        </div>

    </div>

</body>
</html>

header.jsp

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<nav class="navbar navbar-fixed-top navbar-light bg-faded">  
      <a href="#" class="logoHeader-profile">
        <a href="<c:url value="/"/>"><img src="<c:url value="/recursos/img/Dev3.png"/>" /></a><b class="caret"></b>
      </a>       
      <ul class="nav navbar-nav navbar-right">  
        <li class="dropdown">
            <a href="#" class="user-profile dropdown-toggle" data-toggle="dropdown">
                <img src="<c:url value="/recursos/img/img.jpg"/>"class="img-circle"/><b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
                <li>
                    <a href="#">
                    <i class="fa fa-fw fa-user"></i>
                        Perfil
                    </a>
                </li>               
                <li>
                    <a href="#">
                    <i class="fa fa-fw fa-gear"></i> 
                        Configurações
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a href="#">
                    <i class="fa fa-fw fa-power-off"></i> 
                        Sair
                    </a>
                </li>
            </ul>
           </li>
      </ul>
</nav>

Menu.jsp

<nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>  
              <a class="navbar-brand" href="#">G-FINAN</a>              
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">             
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        Despesas 
                        <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Contas a Pagar</a></li>                     
                        <li><a href="#">Contas Pagas</a></li>
                        <li><a href="#">Contas Vencidas</a></li>
                      </ul>
                    </li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        Recebimentos 
                        <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">
                        <li><a href="#">Receitas</a></li>                       
                        <li><a href="#">A Receber</a></li>
                      </ul>
                    </li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        Contas 
                        <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">

                      </ul>
                    </li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        Planejamento 
                        <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">

                      </ul>
                    </li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        Dicas G-Finan 
                        <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">

                      </ul>
                    </li>
                </ul>
            </div>
        </div>  
    </nav>

Page Principál . jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<div class="row tile_count">
        <div class="col-md-12 col-sm-12 col-xs-12">
             <!-- <div class="x_panel"> -->
                <div class="x_title">
                    <h3>                        
                        Resumo Financeiro           
                    </h3>
                </div>
                <div class="x_content">
                    <br/>
                    <div class="col-lg-3 col-xs-6">              
                        <div class="small-box bg-red">
                          <div class="inner">
                            <h3><sup style="font-size: 20px">R$</sup>1.189,80</h3>
                            <p>Total Despesas</p>
                          </div>
                          <div class="icon">
                            <i class="fa fa-calculator"></i>
                          </div>
                          <a href="#" class="small-box-footer">
                            Mais Detalhes <i class="fa fa-arrow-circle-right"></i>
                          </a>
                        </div>
                    </div>
                    <div class="col-lg-3 col-xs-6">
                      <div class="small-box bg-green">
                        <div class="inner">
                          <h3><sup style="font-size: 20px">R$</sup>3.348,00</h3>
                          <p>Total Receitas</p>
                        </div>
                        <div class="icon">
                          <i class="fa fa-usd"></i>
                        </div>
                        <a href="#" class="small-box-footer">
                          Mais Detalhes <i class="fa fa-arrow-circle-right"></i>
                        </a>
                      </div>
                    </div>
                    <div class="col-lg-3 col-xs-6">
                      <div class="small-box bg-aqua">
                        <div class="inner">
                          <h3><sup style="font-size: 20px">R$</sup>44,00</h3>
                          <p>Total Investimento</p>
                        </div>
                        <div class="icon">
                          <i class="fa fa-line-chart"></i>
                        </div>
                        <a href="#" class="small-box-footer">
                          Mais Detalhes <i class="fa fa-arrow-circle-right"></i>
                        </a>
                      </div>
                    </div>
                    <div class="col-lg-3 col-xs-6">
                      <div class="small-box bg-orange">
                        <div class="inner">
                          <h3>65<sup style="font-size: 20px">%</sup></h3>
                          <p>Balanço Médio</p>
                        </div>
                        <div class="icon">
                          <i class="fa fa-balance-scale"></i>
                        </div>
                        <a href="#" class="small-box-footer">
                          Mais Detalhes <i class="fa fa-arrow-circle-right"></i>
                        </a>
                      </div>
                    </div>
                </div>                  
             </div>        
        </div>

Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.pessoal</groupId>
    <artifactId>restauranteWeb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>Sistema Restaurante Web</name>
    <description>Sistema para Restaurantes e Afins</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.2.5.RELEASE</spring.version>
        <hibernate.version>5.1.0.Final</hibernate.version>
        <tiles.version>3.0.5</tiles.version>
    </properties>

    <dependencies>

        <!-- Tiles -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-extras</artifactId>
            <version>${tiles.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>${tiles.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>${tiles.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>
            <version>${tiles.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-el</artifactId>
            <version>${tiles.version}</version>
        </dependency>

        <!-- Javax - Jsf -->
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>jsr250-api</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.19</version>
        </dependency>

        <!-- MySql-Conector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>

        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.3.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> 
            <version>${spring.version}</version> </dependency> -->
        <!-- <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-faces</artifactId> 
            <version>2.3.1.RELEASE</version> </dependency> -->
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <warName>restauranteWeb</warName>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
        <finalName>restaurante</finalName>
    </build>
</project>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.