You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jurrie Overgoor <ju...@2go-mobile.nl> on 2008/11/03 12:20:30 UTC
Repeater with checkbox
Hello everyone,
I'm currently creating a Wicket application, and for this I need a
repeater that lets the user select multiple rows from a list of items.
So basically a repeater that adds a checkbox in front of every item. Is
this component available? I remember seeing this somewhere, but I forgot
where, and I can't seem to find it again.
--
With kind regards,
Jurrie Overgoor
2go-mobile b.v.
Re: Repeater with checkbox
Posted by Hannes Schubert <in...@tele2.de>.
Jurrie,
this goes very well. I use check boxes in repeaters for the same reason.
Just have a look at the following snippets.
....
dynamicContents.add(listView = new DataView("whatever",
getDataProvider(), 15)
{
@Override
protected void populateItem(Item listItem) {
final Whatever whatever =
(Whatever)listItem.getModelObject();
//log.debug("populateItem()
whatever="+whatever.getControlnumber()+" =>
"+selection.contains(whatever.getId()));
final SelectionModel<Whatever> selectionModel = new
SelectionModel<Whatever>(whatever, selection.contains(whatever.getId()));
final CheckBox checkBox = new AjaxCheckBox("selected",
selectionModel) {
@Override
public void onUpdate(AjaxRequestTarget target) {
Boolean selected = selectionModel.getObject();
Long id = selectionModel.getSelection().getId();
if (selected)
selection.add(id);
else
selection.remove(id);
log.debug("selected.onUpdate: "+selected+" for
id="+id);
}
};
checkBox.setOutputMarkupId(true);
checkBox.setVisible(selectionEnabled);
selectionBoxes.put(selectionModel, checkBox);
listItem.add(checkBox);
listItem.add(new Label("dmcControlnumber", new
PropertyModel(whatever, "controlnumber")));
...
This requires a simple class what simply reflects the selection state of
the selected/unselected rows collected in a map. It is a bit tricky if
you start up with some rows already selected and dataproviders
supporting lazy loads . Then you might have to setup the selection
models on creation only for visible rows and merge afterwards.
Best regards
Hannes
Jurrie Overgoor wrote:
> Hello everyone,
>
> I'm currently creating a Wicket application, and for this I need a
> repeater that lets the user select multiple rows from a list of items.
> So basically a repeater that adds a checkbox in front of every item.
> Is this component available? I remember seeing this somewhere, but I
> forgot where, and I can't seem to find it again.
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org