You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Fang Lin <Fa...@u.washington.edu> on 2009/04/29 20:44:19 UTC
Need to Understand CheckGroup and Check
The examples at
http://wicketstuff.org/wicket13/compref/;jsessionid=2AF2BC5B8195BE6BA0EFADE26E35292F?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckGroupPage
and http://cwiki.apache.org/WICKET/listview-with-checkboxes.html provided some help, but don't have enough details, such as how to pre-set the Checkbox to be checked. The CheckGroup is not covered in Wicket books.
Could someone who has used CheckGroup verify if this is the right way to use CheckGroup and Check?
CheckGroup itemGroup = new CheckGroup ("group", selection);
// the selection is a List<Item> representing the possible choices
form.add (itemGroup);
itemGroup.add ( new CheckGroupSelector ("groupselector", itemGroup));
// for (un)check all
// the listOfSelected is a List<Item> representing the items currently checked
ListView itemList = new ListView("item_list", listOfSelected) {
protected void populateItem(ListItem item) {
Item t = (Item)item.getModelObject();
item.add (new Check ("ckbox_item",
item.getModel(),
itemGroup));
item.add (new Label("item_title", t.getName()));
}
};
itemGroup.setReuseItems(true);
itemGroup.add(itemList);
Re: Need to Understand CheckGroup and Check
Posted by "Mathias P.W Nilsson" <ma...@snyltarna.se>.
The selection variable is a collection or a wicket model with an object of
collection. You can preselect you values by using the same classes there.
Consider this
Form<String> form = new Form<String>( "form" );
String[] someStrings = new String[]{ "Wicket" , "Hibernate", "Maven",
"Spring" };
String[] other = new String[]{ "Wicket" , "Hibernate", "Maven", "Spring",
"C#", "NHibernate" };
CheckGroup<String> group = new CheckGroup<String>( "group", Arrays.asList(
someStrings ) );
ListView<String> stringView = new ListView<String>( "stringView" ,
Arrays.asList( other ) ){
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<String> item) {
item.add( new Check<String>( "item", item.getModel() ));
}
};
group.add( stringView );
form.add( group );
add( form );
Here the someStrings will be checked, that is ( "Wicket" , "Hibernate",
"Maven", "Spring" ). NHibernate and C# will not be checked.
Hope this helps.
--
View this message in context: http://www.nabble.com/Need-to-Understand-CheckGroup-and-Check-tp23307190p23311015.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org