NOTE: This is outdated information that applies only to Tapestry 4.

If you (as in my case) want to put some HTML meta tags in your pages AFAIK the easiest solution is to provide a custom delegate to the Shell component which outputs the tags you need.

First you have to define a Shell component in the HTML template (most preferable in the one of a custom Border component):

<span jwcid="$content$">
<html jwcid="shell">
<body jwcid="@Body">
...

In the page specification (or component specification if you use a custom Border component) you have to add the following to bind the delegate bean to the Shell component:

<bean name="shellDelegate" class="ShellDelegate"/>

<component id="shell" type="Shell">
    <binding name="delegate" value="bean:shellDelegate"/>
</component>

An example ShellDelegate bean could look like:

import java.util.Locale;

import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;

public class ShellDelegate implements IRender
{
	public void render(IMarkupWriter writer, IRequestCycle cycle)
	{
		addMetaTag(writer, "copyright", "YOUR_COPYRIGHT_NOTICE");
		addMetaTag(writer, "author", "YOUR_NAME");
		addMetaTag(writer, "robots", "Index,Follow");
		
		Locale locale = cycle.getEngine().getLocale();
		if (locale.getLanguage().equals(new Locale("de", "", "").getLanguage()))
		{
			addMetaTag(writer, "description", "DESCRIPTION");
			addMetaTag(writer, "keywords", "KEYWORDS" );
		}
	}

	private void addMetaTag(IMarkupWriter writer, String key, String value)
	{
		writer.beginEmpty("meta");
		writer.attribute("name", key);
		writer.attribute("content", value);
		writer.print("\n");
	}
}

There's another solution that does NOT require the creation of a custom delegate class.

<span jwcid="$content$">
<html jwcid="shell">
<head jwcid="remainingHead@Block">
  <meta name="copyright" content="YOUR_COPYRIGHT_NOTICE"/>
  <meta name="author" content="YOUR_NAME"/>
  <meta name="robots" content="Index,Follow"/>
  ...
  <link rel="SHORTCUT ICON" href="favicon.ico" />
</head>
<body jwcid="@Body">
...

and then in the page specification:

<component id="shell" type="Shell">
    <binding name="delegate" 
        value="new org.apache.tapestry.components.BlockRenderer(components.remainingHead)"/>
</component>

Or just do this:

<html jwcid="@Shell" title="ognl:title" stylesheet="asset:stylesheet" delegate="component:meta">
    <span jwcid="@If" condition="false">
        <span jwcid="meta@If" condition="true">
            <meta http-equiv="Pragma" content="no-cache" />
            <meta http-equiv="Cache-Control" content="no-cache" />
            <meta http-equiv="Expires" content="Mon, 06 Jan 1990 00:00:01 GMT" />
        </span>
    </span>
    ....
  • No labels