On Thursday, 08 March 2007 07:58 pm, Igor Vaynberg escreveu: > see above. take a simple example where you have a list of checkboxes and > you want all selected objects to end up in a collection. how do you do it? > sounds like a complex mapping? the most elegant way is to write a custom > model.
Can you use a CheckBoxMultipleChoice for this? > > class mypage extends page { > private Set<Person> selected=new HashSet(); > > private class PersonCheckboxModel implements IModel<Boolean> { > private final IModel<Person> person; > public final PersonCheckBoxModel(IModel<Person> person) { > this.person=person; } > > public Boolean getObject() { > return selected.contains(person.getObject()); > } > > public void setObject(Boolean b) { > if (Boolean.TRUE.equals(b)) { > selected.put(person.getObject()); > } else { > selected.remove(person.getObject()); > } > } > > public void detach() { person.detach(); } > } > > } > > now all you have to do is > > LoadableDetachableModel person=new LoadalbeDetachableModel(id); > new CheckBox(this, "cb", new PersonCheckBoxModel(person)); > > and everything magically works, hope it gives you some ideas. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user