我嘗試在一個簡單的自定義組件中設置一個pagelink的動態css類值,並且找不到任何方法。帶動態css類的掛毯pagelink
我的組件......
<!-- 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方式思考。 歡迎提供任何幫助或有用的提示。
而最好使用prop:binding而不是$ {...},例如class =「prop:myDynCss」,http://tapestry.apache.org/component-parameters.html#ComponentParameters-dontUseSyntax – sody
@sody我認爲你在prop:binding這裏是不正確的。對於組件上定義的參數綁定,這是正確的,而不是簡單地將值打印到類屬性的DOM屬性中。 – joostschouten
@joostschouten對於遲到的答覆感到遺憾......並且感謝解決方案。我會試試看。與此同時,另一種方式與afterRender事件。 – OkieOth