Problem Handling a list of Objects in jsp

Asked

Viewed 90 times

0

I’m having trouble handling a list that comes from my controller in my jsp I believe I’m not using the right way to treat and go through this list

follows my controller who 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 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>
  • And what happens? And what do you expect? Please specify your problem.

  • so when I try to climb that way the list doesn’t go to my view

  • i need this list in order to create an element inside the view that has the name and id of the same object

  • can debug this js or view the result of: listName?

  • I can debug js but the result of the list is empty because it seems that the information does not subui

  • And when you debug this: model.addAttribute("listCompletaNomeItos", listCompletaNomeItos) results in the variable?

  • until then the information arrives the problem this up

Show 2 more comments

2 answers

0


Good staff thank you for the most help I managed to resolve using the foreach thank you very much

0

I see that in the 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 be able to read the variable coming from the controller.

  • then João has this and others Aglibs on the page yes friend even so the error continues.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.