In wicket AttributeModifier doesn't change attribute "class" for AjaxLink. It should change class attribute and change how link looks like.
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")));
}
}
}
Corresponding html file looks like:
<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>
Thanks