|
Size: 1528
Comment:
|
← Revision 3 as of 2009-10-20 18:12:02 ⇥
Size: 1546
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 8: | Line 8: |
| {{{ | |
| Line 40: | Line 41: |
| }}} | |
| Line 47: | Line 48: |
| {{{ | |
| Line 59: | Line 61: |
| }}} |
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>