Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
Problem with sending checked checkbox list to controller(Spring MVC)

VO

List<String> status;

Controller

@RequestMapping(value="/ed/statusList",method = RequestMethod.POST)
public @ResponseBody Object statusList(HttpServletRequest request, HttpServletResponse response, CurriculumSearchExt ce) throws JsonGenerationException, JsonMappingException, IOException {
   System.out.println(ce.getStatus());
...
}

javascript

$("input[name='status']:checkbox").on('click', function() {
   var checkArr = [];
   $("input[name='status']:checked").each(function() {
      checkArr.push($(this).val());
   });
   console.log("checkArr:" + checkArr);
   if(checkArr.length == 0) {
      checkArr = [""];
   }
   ...//some other parameters
   formdata = {
      ...
      "status" : checkArr
   };
   $("#gridlist").jqGrid("clearGridParam", true);
   $("#gridlist").jqGrid('setGridParam', {
      url : 'ed/statusList',
      datatype : 'json',
      mtype : 'post',
      postData : formdata,
      ajaxGridOptions : {
         traditional : true,
         complete : function(data) {
            console.log('success');
         }
      }
   }).trigger('reloadGrid');
});

HTML

<input type="checkbox" name="status" value="10">a
<input type="checkbox" name="status" value="20">b
<input type="checkbox" name="status" value="30">c
<input type="checkbox" name="status" value="50">d
<input type="checkbox" name="status" value="60">e

When I check 'a', then checkArr:10 is printed at chrome and [10] is printed at server. I check 'b'('a','b' are checked), then checkArr:10, 20 is printed at chrome and [10, 20] is printed at server. and lastly, here is the problem. When I check 'b' again(only 'a' is checked), then checkArr:10 is printed at chrome and [10, 20] is printed at server. If I check 'b' again and uncheck 'a'(only 'b' is checked), then checkArr:20 is printed at chrome and [20,20] is printed at server.

The list 'checkArr' is normally worked at javascript, but controller can`t receive the right things. I want 'checkArr' to go to controller just the way it is.

If you have other things you nead, please comment. Thanks for read.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda