Thymeleaf th:each repair












0















I am trying to use the th:each function for my site, to find all the dogs in my database, and am using the following code. In my controller, I have:



@Controller
public class DogController {

private DogDatabase database = new DogDatabase();
@RequestMapping(value = "/allDogs", method = RequestMethod.GET)
public String getAllDogs(Model model)
{
ArrayList<Integer> ids = database.getAllIDs();
System.out.println(ids.size());
Dog dogs = new Dog[ids.size()+1];

for(int i = 0; i < ids.size(); ++i)
{
dogs[i] = database.getDog(ids.get(i));
}
model.addAttribute("dogs", dogs);

return "getAllDogs";
}


After this for loop, I did a println on each object in the array and verified, that all my dog objects are valid and not null. After verifying that the array is correct, I am passing it as a model and trying to get it in the html. The current problem is that when I go to the html, it displays nothing. I'm not getting any thymeleaf errors, just a blank screen. Attached is my html code where I call th:each



<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>All Dogs</title>
</head>

<body>
<table>
<th:block th:each="dog : ${dogs}">
<tr>
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</th:block>
</table>
</body>
</html>


Edit One and Two: edit was to fix errors, that was not in my code



Edit Three: I tried switching dog and dogs in the iterator (as in code above,) but now I am getting an error that there was an "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)"



This does not make sense, however, as I use dog.name throughout the site, and getName() is public in Dog class. Upon request, I am adding my dog class: https://pastebin.com/Lknc8dtZ










share|improve this question

























  • Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

    – M. Deinum
    Nov 27 '18 at 19:51











  • Is that comma after dog in the th:each a typo?

    – Catweazle
    Nov 27 '18 at 19:51











  • @Catweazle it was

    – Andre Ellis
    Nov 27 '18 at 19:56











  • I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

    – Andre Ellis
    Nov 27 '18 at 20:00











  • Try adding "return this.name" in the getName() method !

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:43
















0















I am trying to use the th:each function for my site, to find all the dogs in my database, and am using the following code. In my controller, I have:



@Controller
public class DogController {

private DogDatabase database = new DogDatabase();
@RequestMapping(value = "/allDogs", method = RequestMethod.GET)
public String getAllDogs(Model model)
{
ArrayList<Integer> ids = database.getAllIDs();
System.out.println(ids.size());
Dog dogs = new Dog[ids.size()+1];

for(int i = 0; i < ids.size(); ++i)
{
dogs[i] = database.getDog(ids.get(i));
}
model.addAttribute("dogs", dogs);

return "getAllDogs";
}


After this for loop, I did a println on each object in the array and verified, that all my dog objects are valid and not null. After verifying that the array is correct, I am passing it as a model and trying to get it in the html. The current problem is that when I go to the html, it displays nothing. I'm not getting any thymeleaf errors, just a blank screen. Attached is my html code where I call th:each



<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>All Dogs</title>
</head>

<body>
<table>
<th:block th:each="dog : ${dogs}">
<tr>
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</th:block>
</table>
</body>
</html>


Edit One and Two: edit was to fix errors, that was not in my code



Edit Three: I tried switching dog and dogs in the iterator (as in code above,) but now I am getting an error that there was an "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)"



This does not make sense, however, as I use dog.name throughout the site, and getName() is public in Dog class. Upon request, I am adding my dog class: https://pastebin.com/Lknc8dtZ










share|improve this question

























  • Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

    – M. Deinum
    Nov 27 '18 at 19:51











  • Is that comma after dog in the th:each a typo?

    – Catweazle
    Nov 27 '18 at 19:51











  • @Catweazle it was

    – Andre Ellis
    Nov 27 '18 at 19:56











  • I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

    – Andre Ellis
    Nov 27 '18 at 20:00











  • Try adding "return this.name" in the getName() method !

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:43














0












0








0








I am trying to use the th:each function for my site, to find all the dogs in my database, and am using the following code. In my controller, I have:



@Controller
public class DogController {

private DogDatabase database = new DogDatabase();
@RequestMapping(value = "/allDogs", method = RequestMethod.GET)
public String getAllDogs(Model model)
{
ArrayList<Integer> ids = database.getAllIDs();
System.out.println(ids.size());
Dog dogs = new Dog[ids.size()+1];

for(int i = 0; i < ids.size(); ++i)
{
dogs[i] = database.getDog(ids.get(i));
}
model.addAttribute("dogs", dogs);

return "getAllDogs";
}


After this for loop, I did a println on each object in the array and verified, that all my dog objects are valid and not null. After verifying that the array is correct, I am passing it as a model and trying to get it in the html. The current problem is that when I go to the html, it displays nothing. I'm not getting any thymeleaf errors, just a blank screen. Attached is my html code where I call th:each



<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>All Dogs</title>
</head>

<body>
<table>
<th:block th:each="dog : ${dogs}">
<tr>
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</th:block>
</table>
</body>
</html>


Edit One and Two: edit was to fix errors, that was not in my code



Edit Three: I tried switching dog and dogs in the iterator (as in code above,) but now I am getting an error that there was an "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)"



This does not make sense, however, as I use dog.name throughout the site, and getName() is public in Dog class. Upon request, I am adding my dog class: https://pastebin.com/Lknc8dtZ










share|improve this question
















I am trying to use the th:each function for my site, to find all the dogs in my database, and am using the following code. In my controller, I have:



@Controller
public class DogController {

private DogDatabase database = new DogDatabase();
@RequestMapping(value = "/allDogs", method = RequestMethod.GET)
public String getAllDogs(Model model)
{
ArrayList<Integer> ids = database.getAllIDs();
System.out.println(ids.size());
Dog dogs = new Dog[ids.size()+1];

for(int i = 0; i < ids.size(); ++i)
{
dogs[i] = database.getDog(ids.get(i));
}
model.addAttribute("dogs", dogs);

return "getAllDogs";
}


After this for loop, I did a println on each object in the array and verified, that all my dog objects are valid and not null. After verifying that the array is correct, I am passing it as a model and trying to get it in the html. The current problem is that when I go to the html, it displays nothing. I'm not getting any thymeleaf errors, just a blank screen. Attached is my html code where I call th:each



<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>All Dogs</title>
</head>

<body>
<table>
<th:block th:each="dog : ${dogs}">
<tr>
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</th:block>
</table>
</body>
</html>


Edit One and Two: edit was to fix errors, that was not in my code



Edit Three: I tried switching dog and dogs in the iterator (as in code above,) but now I am getting an error that there was an "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)"



This does not make sense, however, as I use dog.name throughout the site, and getName() is public in Dog class. Upon request, I am adding my dog class: https://pastebin.com/Lknc8dtZ







java spring thymeleaf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 20:32







Andre Ellis

















asked Nov 27 '18 at 19:47









Andre EllisAndre Ellis

85




85













  • Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

    – M. Deinum
    Nov 27 '18 at 19:51











  • Is that comma after dog in the th:each a typo?

    – Catweazle
    Nov 27 '18 at 19:51











  • @Catweazle it was

    – Andre Ellis
    Nov 27 '18 at 19:56











  • I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

    – Andre Ellis
    Nov 27 '18 at 20:00











  • Try adding "return this.name" in the getName() method !

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:43



















  • Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

    – M. Deinum
    Nov 27 '18 at 19:51











  • Is that comma after dog in the th:each a typo?

    – Catweazle
    Nov 27 '18 at 19:51











  • @Catweazle it was

    – Andre Ellis
    Nov 27 '18 at 19:56











  • I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

    – Andre Ellis
    Nov 27 '18 at 20:00











  • Try adding "return this.name" in the getName() method !

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:43

















Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

– M. Deinum
Nov 27 '18 at 19:51





Your namespace is wrong. It should read xmlns:th="http://www.thymeleaf.org".

– M. Deinum
Nov 27 '18 at 19:51













Is that comma after dog in the th:each a typo?

– Catweazle
Nov 27 '18 at 19:51





Is that comma after dog in the th:each a typo?

– Catweazle
Nov 27 '18 at 19:51













@Catweazle it was

– Andre Ellis
Nov 27 '18 at 19:56





@Catweazle it was

– Andre Ellis
Nov 27 '18 at 19:56













I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

– Andre Ellis
Nov 27 '18 at 20:00





I added the namespace of xmlns:th="thymeleaf.org, and it did not resolve. @M.Deinum

– Andre Ellis
Nov 27 '18 at 20:00













Try adding "return this.name" in the getName() method !

– Nacho Zve De La Torre
Nov 27 '18 at 20:43





Try adding "return this.name" in the getName() method !

– Nacho Zve De La Torre
Nov 27 '18 at 20:43












2 Answers
2






active

oldest

votes


















3














I believe the problem is here:



<th:block th:each="dogs : ${dog}">


sience in your controller you are binding the Dog array to the variable "dogs":



model.addAttribute("dogs", dogs);


So in your template you should iterate like this:



<th:block th:each="dog : ${dogs}">
<tr>
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</th:block>


to look for each dog in the dogs array :)






share|improve this answer
























  • When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

    – Andre Ellis
    Nov 27 '18 at 20:10











  • That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:22






  • 1





    @AndreEllis is your getName() public in Dog.java?

    – Juan Carlos Mendoza
    Nov 27 '18 at 20:26








  • 1





    @JuanCarlosMendoza and Nacho, I added them above

    – Andre Ellis
    Nov 27 '18 at 20:33






  • 2





    @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

    – Metroids
    Nov 27 '18 at 20:47





















1














There is no reason here to use an array of Dog rather than a List<Dog> -- and that is probably what is causing your error. You are creating an array that is too big, and so it's trying to call getName() on a null object.



@RequestMapping(value = "/allDogs", method = RequestMethod.GET)
public String getAllDogs(Map<String, Object> model) {
List<Dog> dogs = database.getAllIDs()
.stream()
.map(id -> database.getDog(id))
.collect(Collectors.toList());
model.put("dogs", dogs);
return "getAllDogs";
}


Also, you have don't need the extra <th:block />. You can move the th:each directly onto the <tr>.



<table>
<tr th:each="dog : ${dogs}">
<td>Name: </td>
<td th:text="${dog.name}">Name</td>
</tr>
</table>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53507056%2fthymeleaf-theach-repair%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    I believe the problem is here:



    <th:block th:each="dogs : ${dog}">


    sience in your controller you are binding the Dog array to the variable "dogs":



    model.addAttribute("dogs", dogs);


    So in your template you should iterate like this:



    <th:block th:each="dog : ${dogs}">
    <tr>
    <td>Name: </td>
    <td th:text="${dog.name}">Name</td>
    </tr>
    </th:block>


    to look for each dog in the dogs array :)






    share|improve this answer
























    • When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

      – Andre Ellis
      Nov 27 '18 at 20:10











    • That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

      – Nacho Zve De La Torre
      Nov 27 '18 at 20:22






    • 1





      @AndreEllis is your getName() public in Dog.java?

      – Juan Carlos Mendoza
      Nov 27 '18 at 20:26








    • 1





      @JuanCarlosMendoza and Nacho, I added them above

      – Andre Ellis
      Nov 27 '18 at 20:33






    • 2





      @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

      – Metroids
      Nov 27 '18 at 20:47


















    3














    I believe the problem is here:



    <th:block th:each="dogs : ${dog}">


    sience in your controller you are binding the Dog array to the variable "dogs":



    model.addAttribute("dogs", dogs);


    So in your template you should iterate like this:



    <th:block th:each="dog : ${dogs}">
    <tr>
    <td>Name: </td>
    <td th:text="${dog.name}">Name</td>
    </tr>
    </th:block>


    to look for each dog in the dogs array :)






    share|improve this answer
























    • When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

      – Andre Ellis
      Nov 27 '18 at 20:10











    • That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

      – Nacho Zve De La Torre
      Nov 27 '18 at 20:22






    • 1





      @AndreEllis is your getName() public in Dog.java?

      – Juan Carlos Mendoza
      Nov 27 '18 at 20:26








    • 1





      @JuanCarlosMendoza and Nacho, I added them above

      – Andre Ellis
      Nov 27 '18 at 20:33






    • 2





      @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

      – Metroids
      Nov 27 '18 at 20:47
















    3












    3








    3







    I believe the problem is here:



    <th:block th:each="dogs : ${dog}">


    sience in your controller you are binding the Dog array to the variable "dogs":



    model.addAttribute("dogs", dogs);


    So in your template you should iterate like this:



    <th:block th:each="dog : ${dogs}">
    <tr>
    <td>Name: </td>
    <td th:text="${dog.name}">Name</td>
    </tr>
    </th:block>


    to look for each dog in the dogs array :)






    share|improve this answer













    I believe the problem is here:



    <th:block th:each="dogs : ${dog}">


    sience in your controller you are binding the Dog array to the variable "dogs":



    model.addAttribute("dogs", dogs);


    So in your template you should iterate like this:



    <th:block th:each="dog : ${dogs}">
    <tr>
    <td>Name: </td>
    <td th:text="${dog.name}">Name</td>
    </tr>
    </th:block>


    to look for each dog in the dogs array :)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 27 '18 at 20:03









    Nacho Zve De La TorreNacho Zve De La Torre

    18710




    18710













    • When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

      – Andre Ellis
      Nov 27 '18 at 20:10











    • That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

      – Nacho Zve De La Torre
      Nov 27 '18 at 20:22






    • 1





      @AndreEllis is your getName() public in Dog.java?

      – Juan Carlos Mendoza
      Nov 27 '18 at 20:26








    • 1





      @JuanCarlosMendoza and Nacho, I added them above

      – Andre Ellis
      Nov 27 '18 at 20:33






    • 2





      @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

      – Metroids
      Nov 27 '18 at 20:47





















    • When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

      – Andre Ellis
      Nov 27 '18 at 20:10











    • That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

      – Nacho Zve De La Torre
      Nov 27 '18 at 20:22






    • 1





      @AndreEllis is your getName() public in Dog.java?

      – Juan Carlos Mendoza
      Nov 27 '18 at 20:26








    • 1





      @JuanCarlosMendoza and Nacho, I added them above

      – Andre Ellis
      Nov 27 '18 at 20:33






    • 2





      @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

      – Metroids
      Nov 27 '18 at 20:47



















    When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

    – Andre Ellis
    Nov 27 '18 at 20:10





    When I try that, I get "Exception evaluating SpringEL expression: "dog.name" (template: "getAllDogs" - line 13, col 21)," but I know that dog.name is appropriate, as I use it in other html files, and I do have a name field in my Dog.java class with a matching getName()

    – Andre Ellis
    Nov 27 '18 at 20:10













    That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:22





    That's weird ... I'm a newbie too, sorry I can't help you much :( The iteration was wrong thought, you should do it as I've posted. Maybe you can share you Dog class ?

    – Nacho Zve De La Torre
    Nov 27 '18 at 20:22




    1




    1





    @AndreEllis is your getName() public in Dog.java?

    – Juan Carlos Mendoza
    Nov 27 '18 at 20:26







    @AndreEllis is your getName() public in Dog.java?

    – Juan Carlos Mendoza
    Nov 27 '18 at 20:26






    1




    1





    @JuanCarlosMendoza and Nacho, I added them above

    – Andre Ellis
    Nov 27 '18 at 20:33





    @JuanCarlosMendoza and Nacho, I added them above

    – Andre Ellis
    Nov 27 '18 at 20:33




    2




    2





    @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

    – Metroids
    Nov 27 '18 at 20:47







    @NachoZveDeLaTorre I'm guessing it's because your array has a null object. you're making it one bigger than ids.size() and so on the last iteration of the th:each, you are calling getName() on a null object.

    – Metroids
    Nov 27 '18 at 20:47















    1














    There is no reason here to use an array of Dog rather than a List<Dog> -- and that is probably what is causing your error. You are creating an array that is too big, and so it's trying to call getName() on a null object.



    @RequestMapping(value = "/allDogs", method = RequestMethod.GET)
    public String getAllDogs(Map<String, Object> model) {
    List<Dog> dogs = database.getAllIDs()
    .stream()
    .map(id -> database.getDog(id))
    .collect(Collectors.toList());
    model.put("dogs", dogs);
    return "getAllDogs";
    }


    Also, you have don't need the extra <th:block />. You can move the th:each directly onto the <tr>.



    <table>
    <tr th:each="dog : ${dogs}">
    <td>Name: </td>
    <td th:text="${dog.name}">Name</td>
    </tr>
    </table>





    share|improve this answer




























      1














      There is no reason here to use an array of Dog rather than a List<Dog> -- and that is probably what is causing your error. You are creating an array that is too big, and so it's trying to call getName() on a null object.



      @RequestMapping(value = "/allDogs", method = RequestMethod.GET)
      public String getAllDogs(Map<String, Object> model) {
      List<Dog> dogs = database.getAllIDs()
      .stream()
      .map(id -> database.getDog(id))
      .collect(Collectors.toList());
      model.put("dogs", dogs);
      return "getAllDogs";
      }


      Also, you have don't need the extra <th:block />. You can move the th:each directly onto the <tr>.



      <table>
      <tr th:each="dog : ${dogs}">
      <td>Name: </td>
      <td th:text="${dog.name}">Name</td>
      </tr>
      </table>





      share|improve this answer


























        1












        1








        1







        There is no reason here to use an array of Dog rather than a List<Dog> -- and that is probably what is causing your error. You are creating an array that is too big, and so it's trying to call getName() on a null object.



        @RequestMapping(value = "/allDogs", method = RequestMethod.GET)
        public String getAllDogs(Map<String, Object> model) {
        List<Dog> dogs = database.getAllIDs()
        .stream()
        .map(id -> database.getDog(id))
        .collect(Collectors.toList());
        model.put("dogs", dogs);
        return "getAllDogs";
        }


        Also, you have don't need the extra <th:block />. You can move the th:each directly onto the <tr>.



        <table>
        <tr th:each="dog : ${dogs}">
        <td>Name: </td>
        <td th:text="${dog.name}">Name</td>
        </tr>
        </table>





        share|improve this answer













        There is no reason here to use an array of Dog rather than a List<Dog> -- and that is probably what is causing your error. You are creating an array that is too big, and so it's trying to call getName() on a null object.



        @RequestMapping(value = "/allDogs", method = RequestMethod.GET)
        public String getAllDogs(Map<String, Object> model) {
        List<Dog> dogs = database.getAllIDs()
        .stream()
        .map(id -> database.getDog(id))
        .collect(Collectors.toList());
        model.put("dogs", dogs);
        return "getAllDogs";
        }


        Also, you have don't need the extra <th:block />. You can move the th:each directly onto the <tr>.



        <table>
        <tr th:each="dog : ${dogs}">
        <td>Name: </td>
        <td th:text="${dog.name}">Name</td>
        </tr>
        </table>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 15:50









        MetroidsMetroids

        7,15421226




        7,15421226






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53507056%2fthymeleaf-theach-repair%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks