我尝试在一个简单的自定义组件中为页面链接设置动态 css 类值,但找不到任何方法。
我的组件...
<!-- my component template 'testLink' -->
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<!-- maybe I can set here something dynamic like that ...
<t:pagelink page="mytest" t:id="myLink" class="${myDynCss}">
... but in this case I need to pass the parameter what link is handled
-->
<t:pagelink page="mytest" t:id="myLink">
I want dynamic css class
</t:pagelink>
</html>
组件java代码...
public class TestLink {
@Parameter(required=true)
private int activeId;
@Component
PageLink myLink;
public int getActiveId() {
return activeId;
}
public void setupRender()
{
// I try to set some class attribute here but I find no matching function in myLink
// myLink.setCssStyle();
}
public String getMyDynCss(int currentLinkId) {
if (currentLinkId==activeId)
return "active";
else
return "xxx";
}
}
包含组件的页面...
<html t:type="layout" title="Test" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<p:app_navigation>
<t:testLink activeId="1000"/>
</p:app_navigation>
</html>
也许是一个愚蠢的新手问题,但我仍然有问题要以 Tapestry 的方式思考。欢迎任何帮助或有用的提示。