title: Values of checkboxes not saved in database
body: <p>I have a jsp page on which there are various checkboxes.</p>
  
  <p>Some of checkboxes are disabled by default and are already selected.  There is an option to create a new template and assign values to checkboxes. These values are saved into a DB.  </p>
  
  <p>My problem is that saved values of selected checkboxes are always two less than values that were selected by the user.  On debugging the java code, I found that the passed values were as selected by the user.  But the values of the disabled checkboxes are saved to the DB, and the last two values selected by the user are not saved to the DB.</p>
  
  <p>I am hereby attaching the code which picks the selected values and code which saves the values of checkboxes.</p>
  
  <p>Code to pick selected checkbox values.</p>
  
  <pre><code>public ActionForward listSave(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response)
          throws Exception {
  
      HardwareKey key = SecurityUtils.getKeySecurity();
      key.isFeaturePresent(HardwareKey.WS_DATA_EXCHANGE);
  
      DataExchangeTemplateForm thisForm = (DataExchangeTemplateForm) form;
      DataExchangeService service = (DataExchangeService) ServiceLocator
              .getServiceWithName(DataExchangeService.class.getName());
      ActionMessages errors = new ActionMessages();
      Integer dexTemplateId = thisForm.getTemplateId();
  
      String[] paramValues = request.getParameterValues("isRequiredFlag");
      String[] fieldIds = request.getParameterValues("fieldId");
      String[] dataTypeIds = request
              .getParameterValues("dexDataType.dataTypeId");
      String templateType = request.getParameter("templateType");
      boolean isDexTemplate = false;
  
      String direction = thisForm.getDirection();
      String dexTemplateName = thisForm.getDexTemplateName();
      if (Validator.isNullOrEmpty(dexTemplateName)) {
          ActionMessage msg = new ActionMessage("error.data.exchange",
                  " Template name Can't be empty");
          errors.add("error.data.exchange", msg);
          saveErrors(request, errors);
          return view(mapping, form, request, response);
      }
      String dexTemplateVersion = thisForm.getDexVersion();
      if (Validator.isNotNullGreaterThanZero(dexTemplateId)) {
          DexTemplate dexTemplateOld = (DexTemplate) service.getObject(
                  DexTemplate.class, dexTemplateId);
          String profileNameOld = dexTemplateOld.getDescription();
          if (!dexTemplateName.equalsIgnoreCase(profileNameOld)
                  &amp;&amp; service.isDuplicateTemplateName(dexTemplateName)) {
              ActionMessage msg = new ActionMessage("error.data.exchange",
                      "Duplicate Template name");
              errors.add("error.data.exchange", msg);
              saveErrors(request, errors);
              return view(mapping, form, request, response);
          }
  
          service.updateDexTemplateAndParams(dexTemplateName, direction,
                  dexTemplateId, dataTypeIds, paramValues, fieldIds,
                  dexTemplateVersion);
      } else {
  
          if (!service.isDuplicateTemplateName(dexTemplateName)) {
              if(templateType != null &amp;&amp; templateType.equals("extranetDex")) {
                  isDexTemplate = true;
              }
              dexTemplateId = service.saveDataExchangeTemplate(
                      dexTemplateName, direction, dexTemplateVersion, isDexTemplate);
              // saving params...             
              service.saveDexTemplateParams(dexTemplateId, dataTypeIds,
                      paramValues, fieldIds);
          } else {
              ActionMessage msg = new ActionMessage("error.data.exchange",
                      "Duplicate Template name");
              errors.add("error.data.exchange", msg);
              saveErrors(request, errors);
              return view(mapping, form, request, response);
          }
      }
  </code></pre>
  
  <p>Code To Save Selected Checkbox values:</p>
  
  <pre><code>public void saveDexTemplateParams(Integer dexTemplateId,
          String[] dataTypeIds, String[] paramValues, String[] fieldIds)
          throws BaajaException {
  
      DexTemplate dexTemplate = (DexTemplate) getObject(DexTemplate.class,
              dexTemplateId);
      hibernateInitialize(dexTemplate);
      int fieldOrder = 1;
      if(paramValues!=null){
      for (int i = 0; i &lt; paramValues.length; i++) {
          if (!Validator.isNullOrEmpty(paramValues[i])
                  &amp;&amp; paramValues[i].equalsIgnoreCase("true")) {
  
              DexTemplateField templatefield = new DexTemplateField();
              DexField dexField = (DexField) getObject(DexField.class,
                      Integer.parseInt(fieldIds[i]));
  
              templatefield.setDexField(dexField);
              templatefield.setDexTemplate(dexTemplate);
              templatefield.setFieldOrder(fieldOrder++);
  
              saveObject(templatefield);
          }
  </code></pre>
  
  <p>Pls Suggest any possible solution.</p>