在wicket中,AttributeModifier不會更改AjaxLink的屬性「class」。它應該改變類屬性並改變鏈接的樣子。AjaxLink的Wicket AttributeModifier
public class TestPage extends WebPage {
private AjaxLink link1;
private AjaxLink link2;
public TestPage() {
super();
link1 = new AjaxLink("link1") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
switchView("view1");
}
};
link2 = new AjaxLink("link2") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
switchView("view2");
}
};
link1.setOutputMarkupId(true);
link2.setOutputMarkupId(true);
link1.add(new AttributeModifier("class", true, new Model<String>("active")));
link2.add(new AttributeModifier("class", true, new Model<String>("inactive")));
add(link1);
add(link2);
}
private void switchView(String viewName) {
if (viewName.equals("view1")) {
link1.add(new AttributeModifier("class", true, new Model<String>("active")));
link2.add(new AttributeModifier("class", true, new Model<String>("inactive")));
} else if (viewName.equals("view2")) {
link1.add(new AttributeModifier("class", true, new Model<String>("inactive")));
link2.add(new AttributeModifier("class", true, new Model<String>("active")));
}
}
}
相應的HTML文件看起來像:
<html xmlns:wicket>
<body>
<wicket:extend>
<div id="tabs">
<ul>
<li><a wicket:id="link1">View1</a></li>
<li><a wicket:id="link2">View2</a></li>
</ul>
</div>
</wicket:extend>
</body>
</html>
感謝
D'oh!我沒有和wicket一起工作,忘記了addComponent()方法。有用。謝謝 – zinovii 2010-08-31 12:07:34
那麼在這個例子中,target.addComponent()行是否在switchView()之前? – 2016-11-02 11:53:09