public class Test_checkBox extends BasePage {
private Form form;
private static List li = new ArrayList();
private static Map NAMES = new HashMap();
static {
li.add("http://www.sina.com.cn");
li.add("http://www.sohu.com");
li.add("http://www.163.com"); //这样直接显示出来的就是网址
NAMES.put("http://www.sina.com.cn", "新浪"); //显示汉字
NAMES.put("http://www.sohu.com", "搜虎");
NAMES.put("http://www.163.com", "网易");
}
IChoiceRenderer renderer = new ChoiceRenderer() { //使用这个接口来显示上面的文字
public Object getDisplayValue(Object object) {
return NAMES.get(object);
}
};
CheckBoxMultipleChoice siteChoice = new CheckBoxMultipleChoice("cb",li,renderer);
//添加上renderer这个对象
public Test_checkBox() {
super();
form = new Form("myForm"){
@Override
protected void onSubmit() {
System.out.print(siteChoice.getValue());
// System.out.print((List)siteChoice.getDefaultModelObject());
super.onSubmit();
}
};
this.add(form);
form.add(siteChoice);
}
}
test
<input type="submit" value="tijiao"/>
</form>