我也遇到同样的问题,虽然在Action里面自行处理可以解决,但是方法不是很简便,应该在formBean里面可以设置的,等待高手解决。

解决方案 »

  1.   

    在JSP中:
    <html:html>
    <head>
    <title></title>
    <html:base/>
    </head>
    <body bgcolor="white">
    <html:form  action="/wcAction.do"    method="post">
          <html:text property="mybeanvariable1" />
          <html:checkbox  property="chec"  value="123" />
          <html:checkbox  property="chec"  value="444" />
          <html:submit value="提交" />
          <html:reset value="重写" />
      </html:form>
    </body>
    </html:html>/////////////
    在FormAction中:
      private String chec;    //myfiledata;        public String getChec()
            {
                return (this.chec);
            }        public void setChec(String chec)
            {
                this.chec=chec;
            }
    ///////////////////////////////
    在Action中:
     //函数定义:
        public ActionForward execute(ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
    throws Exception 
        {
    // Extract attributes and parameters we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);
    HttpSession session = request.getSession();
    wcForm m_wcForm = (wcForm) form;
    String chec=m_wcForm.getChec();
    if(chec.equals("123"))
    {
        m_wcForm.setChec("123");
     }
     else
     {    m_wcForm.setChec("444");
     }
    ................
    /////////////////////////////
    可实现两个checkbox的选中一个。
    如果只定义一个checkbox,会出现楼主说的现象,只能在Action中根据需要进行设置。
      

  2.   

    你在actionform的类中重载reset方法,将chkCheckbox赋值为null就好了。
    chkCheckbox = null;
    注意:如果有多个checkbox控件,struts只递交当前选中的控件。并且赋值为on或者你指定的value。其他没选中的checkbox控件不会产生递交的动作,所以你要在reset方法中清空以前的数据。
      

  3.   

    public void reset(ActionMapping mapping, HttpServletRequest request) {
    checkboxInput = new String();
    }
    或者:
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    checkboxInput = null;
    }
      

  4.   

    如果你看了struts的文档知道了,可能是faq里面。
    you can write initialize(ActionMapping mapping) in you reset method, like:
    public void reset(ActionMapping mapping, HttpServletRequest request) {
             initialize(mapping);
         }
         ////
    ///ActionForm: reset
      public void reset(ActionMapping mapping, HttpServletRequest request) {
             ;       // Default implementation does nothing
         }
        
    ///DynaActionForm: initialize(ActionMapping mapping)
    public void initialize(ActionMapping mapping) {
    String name = mapping.getName();
    if (name == null) {
    return;
    }
    FormBeanConfig config =mapping.getModuleConfig().findFormBeanConfig(name);
    if (config == null) {
    return;
    }
    FormPropertyConfig props[] = config.findFormPropertyConfigs();
    for (int i = 0; i < props.length; i++) {
    set(props[i].getName(), props[i].initial());
    }
    }
    ///DynaActionForm: reset
    public void reset(ActionMapping mapping, HttpServletRequest request) {
             ;       // Default implementation does nothing
         }
      

  5.   

    如果只有一个页面的话这样做没有问题,
    但是如果页面数据有前页次页的情况就不好处理了。
    如果清空的话前页的选中项目也清空了,
    如果不在reset()里面清空的话,
    前页次页的选中项目只会越来越多,
    如果把选中的再去掉的话,
    Action里面是得不到的。
      

  6.   

    最好不用这个,用multicheckbox,不知道拼错没有。
      

  7.   

    用multibox 可以实现自动保存的功能?是多页那种的也可以吗?
      

  8.   

    multibox在没有选中的情况下
    不是也不提交吗
      

  9.   

    还是用 tyouvivi(tyouvivi) 说的方法把当前页的数据清空其它页的保存就可以了谢谢各位了