1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | // 首先我们需要创建这个 action 对应的 Panel 容器。 private class ActionPanel extendsPanel { public ActionPanel(String id, finalIModel<ProductBean> model) { super(id, model); /* 这个是给 Panel 里面添加各个 link 标签,在各自的 onclick 事件里来做自己的 逻辑处理,同时 model.getObject() 通过这个方法我们就可以拿到绑定到当 前 Panel 上的 Model 对象,一般我们会绑定当前行对应的 databean。*/ add(newLink<ProductBean>("Startup", model) { @Override public void onClick() { ProductBean pb = model.getObject(); } }); add(newLink<ProductBean>("Shutdown", model) { @Override public voidonClick() { ProductBean pb = model.getObject(); } }); add(newLink<ProductBean>("Delete", model) { @Override public void onClick() { ProductBean pb = model.getObject(); } }); } } // 对于 column 的设定,同样的利用 column 的 populateItem 方法对 actions 设置 Panel。 columns.add(newAbstractColumn<ProductBean>(newModel<String>("Actions")){ public void populateItem( Item<ICellPopulator<ProductBean>> cellItem, String componentId, IModel<ProductBean> model) { cellItem.add(newActionPanel(componentId, model)); } }); |
1 2 3 4 5 | <wicket:panel xmlns:wicket="http://wicket.apache.org"> <a href="#"wicket:id="Startup">Startup</a> | <a href="#"wicket:id="Shutdown">Shutdown</a> | <a href="#"wicket:id="Delete">Delete</a> </wicket:panel> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | protected class EmailAddressValidatorEx extendsEmailAddressValidator { @Override protected void onValidate(IValidatable<String> validatable) { String[] mails = validatable.getValue().split(","); for(String mail : mails) { Validatable<String> vMail = newValidatable<String>(mail); vMail.setModel(validatable.getModel()); super.onValidate(vMail); if(vMail.getErrors().size() > 0) { ValidationError vee = newValidationError(); // 其实这个地方我们也可以直接设置 message,而不是 // 从 properties 去取 message,当然是不在需要国际化的时候。 //vee.setMessage(mail + " is not a valid email address."); vee.addMessageKey("EmailAddressValidatorEx"); validatable.error(vee); } } } } // 使用的地方我们只需要对 components 加入这个 validator 就可以了。 taskForm.add(new TextField<String>("reportTo").add(new EmailAddressValidatorEx())); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |