可以当做书签的连接:add(new BookmarkablePageLink("admin",Admin.class));定义行为的连接:Link link1 = new Link("link1") { public void onClick() { count1.clicks++; } }; add(link1);实现一个自定义连接:class CustomLink extends Link { final ClickCount count2; /** * Construct. * @param id */ public CustomLink(String id) { super(id); count2 = new ClickCount(); add(new ClickCountLabel("label2", count2)); } public void onClick() { count2.clicks++; } } add(new CustomLink("link2"));按钮作为连接:// and if we know we are going to attach it to a <input type="button> tag, we shouldn't // use a label, but an AttributeModifier instead. class ButtonLink extends Link { final ClickCount count3; /** * Construct. * @param id */ public ButtonLink(String id) { super(id); count3 = new ClickCount(); add(new AttributeModifier("value", new Model() { public Object getObject(Component component) { // we just replace the whole string. You could use custom // AttributeModifiers to e.g. just replace one part of the // string if you want return "this button is clicked " + count3.clicks + " times"; } })); } public void onClick() { count3.clicks++; } } add(new ButtonLink("link3")); |