Domanda

I'm using CheckGroup and Check to set up a listview of CheckBoxes. The Wicket example show the checkboxes unchecked by default: Wicket Checkgroup Example

I've been looking and testing for a while, but mine are checked by default and I need them to be unchecked.

Here is my code (Note that it's a custom class which i'll add to a form later):

private CheckGroup<String> checks;
private List<String> propertyColumnNames;
private Map<String, String> readableColumnNames;

checks = new CheckGroup<String>("checkGroup", propertyColumnNames);

ListView<String> checksList = new ListView<String>("columns", propertyColumnNames) {
  private static final long serialVersionUID = 1L;

  @Override
  protected void populateItem(ListItem<String> item) {
    Check<String> check = new Check<String>("check", item.getModel());
    check.setLabel(new Model<String>(readableColumnNames.get(item.getModel().getObject())));
    item.add(check);
    item.add(new SimpleFormComponentLabel("column", check));
  }
};
checksList.setReuseItems(true);
checks.add(checksList);
add(checks);

How can I get them unchecked by default ?

Regards,

È stato utile?

Soluzione

The problem is here:

checks = new CheckGroup<String>("checkGroup", propertyColumnNames);

Here you're telling CheckGroup to check every checkbox which is in propertyColumnNames. You need to give an empty collection as the model to CheckGroup.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top