wicket中checkBox框中CheckBoxMultipleChoice如何取出页面上选中的值

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jp.co.infomart.foods.common.admin.page.BasePage;

import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.PropertyModel;

/**
*
* @author admin
*/
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);
        }
        };
     checkBoxModel cbmodel = new checkBoxModel();
        CheckBoxMultipleChoice siteChoice = new CheckBoxMultipleChoice("cb",new PropertyModel(cbmodel,"choList"),li,renderer); 
      
        //添加上renderer这个对象
    public Test_checkBox() {
        super();
     
        form = new Form("myForm"){
  
            @Override
            protected void onSubmit() {
               List list  =  cbmodel.getChoList();
              
                for(int i = 0;i<list.size();i++){
                System.out.print(list.get(i).toString());
               
               }
                super.onSubmit();
            }
       
        };

        this.add(form);   
        form.add(siteChoice);

    }
       
}






<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onUnload="fCloseWin()">
    <form wicket:id="myForm">
        <span wicket:id="cb"></span>
   
        <input type="submit" value="tijiao"/>
    </form>
</body>
</html>






import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
*
* @author admin
*/
public class checkBoxModel implements Serializable{
  private  List choList = new ArrayList();

    public List getChoList() {
        return choList;
    }

    public void setChoList(List choList) {
        this.choList = choList;
    }
 
}

你可能感兴趣的:(checkbox)