爪哇
@Inject
private ComponentResources resources;
public boolean isActiveMenuItemIndex() {
String item = resources.getPageName().toString();
return item.contains("Index");
}
TML
<t:if test="${activeMenuItemIndex}">
<li class="active">
<t:pageLink page="Index">Index</t:pageLink>
</li>
<p:else>
<li>
<t:pageLink page="Index">Index</t:pageLink>
</li>
</p:else>
</t:if>
这是我的第一个想法,它有效,但是您必须为每个项目创建一个单独的方法,并t:if
在 TML 中为每个项目使用一个标签。你对这个问题有更好的解决方案吗?