0
votes

I want to display <title> elements with proper values in html pages. I have one base layout jsp and a corresponding tiles definition. I'd like to set the value of the <title> tag on a per page basis, possibly in the tile definition xml.

So far I have the following

tiles.xml:

<definition name="base" template="/WEB-INF/jsp/layouts/base.jsp">
    <put-attribute name="page-title" value="" />
</definition>

<definition name="home" extends="base">
    <put-attribute name="page-title" value="Homepage" />
</definition>

base.jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><tiles:insertAttribute name="title" ignore="true" /></title>

    ...

The title attribute set in the home definition is not displayed. But why not? What is the correct way to do this?

1

1 Answers

0
votes

You're using the tiles attribute "page-title" as a string, while the default behaviour is to treat it as a template (and that template can't be found and you've chosen to ignore that failure).

Either declare the attribute as type="string", eg

<definition name="base" template="/WEB-INF/jsp/layouts/base.jsp">
    <put-attribute name="page-title" value="" type="string"/>
</definition>

<definition name="home" extends="base">
    <put-attribute name="page-title" value="Homepage" type="string" />
</definition>

Or explicitly use the attribute as a string, eg

<tiles:getAsString name="title" />