MenuItem.java
The className property will return the currentPage className for the html tags when the pagename matches the current node we render
import org.apache.tapestry5.BindingConstants; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.annotations.Property; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; public class MenuItem { @Property @Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL) private String page; @Property @Parameter(required = false, allowNull = true, defaultPrefix = BindingConstants.LITERAL) private boolean isPage = true; @Inject private Messages messages; @Inject private ComponentResources resources; public String getPageTitle() { String key = page + "-title"; return messages.get(key); } public String getClassName() { if (resources.getPageName().equalsIgnoreCase(page)) { return "selected"; } return null; } }
MenuItem.tml
<li xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <t:if test="isPage"> <t:pageLink page="${page}" class="${className}">${pageTitle}</t:pageLink> <p:else> <a href="#" class="${className}">${pageTitle}</a> </p:else> </t:if> <ul> <t:body/> </ul> </li>