Problem Handling a list of Objects in jsp

0

I'm trying to troubleshoot a list that comes from my controller in my jsp I believe I am not using the right way to treat and go through this list.

Follow my controller that creates the list.

@RequestMapping(value = "/show/{id}", method = RequestMethod.GET)
public ModelAndView viewPesquisar(@PathVariable("id") Long id, ModelMap model, HttpServletRequest request) {

    LOGGER.debug(" O id a ser consultado é {}", id);

    List<Ito> optional = itoService.findByIdFetchAll(id);

    if (optional.isEmpty()) {

        LOGGER.debug(" Não foi possivel localizar o Tipo com o Id:{}", id);

        throw new BusinessException("Não foi possivel Localizar o Tipo de Projeto");
    }



    List<Ito> listaCompletaNomeItos = itoService.findByIdFetchAll(id);



    model.addAttribute("listaCompletaNomeItos", listaCompletaNomeItos);

and the jsp where I should treat the list.

   <script>



        console.log("${listaNomeItos}");
        listaNomeItosSpringArray = "${listaNomeItos}";
        listaNomeItosSpringArray = listaNomeItosSpringArray
                .replace("]", "");
        listaNomeItosSpringArray = listaNomeItosSpringArray
                .replace("[", "");
        listaNomeItos= listaNomeItosSpringArray.split(",");



        $
                .each(
                        listaNomeItos,
                        function(k, v) {
                        console.log(v);
                            $("#containerItos")
                                    .append(

            '<div class="col-lg-4 col-md-4 col-sm-12">'+
                 '<div class="card card-stats">'+
                     '<div class="card-header" data-background-color="green">'+
                        ' <i class="fa fa-hdd-o "></i>'+
                     '</div>'+
                      '<div class="card-content">'+
                    '<p class="category">Empz</p>'+
                        '<h4 class="title">'+ v +'</h4>'+

                      '</div>'+
                      '<div class="card-footer">'+
                      '<div class="stats">'+
                            '<i class="fa fa-file-text-o "Style="color: LightSeaGreen";></i> <a href="${uploadIto}"> Upload de Itos </a>'+
                      '</div>'+
                 '</div>'+
               '</div>'+
           '</div>');
    console.log($.trim(v));
    console.log($.trim(k));
                        });


    </script>
    
asked by anonymous 12.06.2017 / 15:12

2 answers

0

Well thanks guys for the help I was able to solve using forEach thank you very much

    
14.06.2017 / 17:13
0

I see that in controller your list receives the objects but in jsp it arrives empty. Check if you are calling the jstl taglib in jsp.

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

If jsp is missing, the page will not read the variable that comes from the controller.

    
14.06.2017 / 00:49