1

ジャワ

@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 でタグを使用する必要があります。この問題のより良い解決策はありますか?

4

2 に答える 2

3

TML

<t:loop source="pages" item="page">
    <li class="${liClass}">
        <t:pageLink page="prop:page">${page}</t:pageLink>
    </li>
</t:loop>

ジャワ

@Inject
private ComponentResources resources;

@Property
private String page;

public String[] getPages() {
     return new String[] { "Index", "Foo", "Bar" };
}

public String getLiClass() {
    return page.equals(resources.getPageName()) ? "active" : "inactive";
}
于 2013-04-27T07:03:04.293 に答える