1

I'm using Apache Tile in Spring Web App, I have to include some dependencies under certain conditions,

So I want to know if in file "tiles.xml" we can set some conditions as below ?

<definition name=".tpl1" extends=".MainTpl"
    template="/WEB-INF/views/templates/tpl1.jsp">
    <put-attribute name="header" value="XX" />
    <put-attribute name="dashboard" value="XX" />
    <if [Some condition] >
       <put attribute name="isOk" value="XX />
    />
    <else>
       <put-attribute name="isNok" value="YY" />
    />
</definition>

I'm really not sure about this part but I want to know if it's possible or not :)

Kind regards :)

MrGlode
  • 31
  • 1

2 Answers2

0

There is no condition in Apache Tiles. Instead you can compose your definition like this :

<definition name=".tpl1" extends=".MainTpl"
    template="/WEB-INF/views/templates/tpl1.jsp">
    <put-attribute name="header" value="XX" />
    <put-attribute name="dashboard" value="XX" />
    <put-attribute name="condition" value="condition.jsp" />
    <put-attribute name="isOk" value="XX" />
    <put-attribute name="isNOk" value="XX" />
</definition>

And in condition.jsp have something like this

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<c:choose>
    <c:when test="[some condition]">
        <tiles:insertAttribute name="isOk">
    </c:when>
    <c:otherwise>
        <tiles:insertAttribute name="isNOk">
    </c:otherwise>
</c:choose>
Dalc
  • 1,138
  • 8
  • 10
  • Yeah I know Jstl's conditions, but it was a question that I have to explain :) But thanks to take time for answer it :) – MrGlode Jul 21 '16 at 14:11
0

Your question is very similar to this, you can refer to the answer there.

Sam YC
  • 10,725
  • 19
  • 102
  • 158