Thymeleaf th:each repair
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
|
show 1 more comment
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
Your namespace is wrong. It should readxmlns: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
|
show 1 more comment
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
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
java spring thymeleaf
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 readxmlns: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
|
show 1 more comment
Your namespace is wrong. It should readxmlns: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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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 :)
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 yourgetName()
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 thanids.size()
and so on the last iteration of theth:each
, you are callinggetName()
on a null object.
– Metroids
Nov 27 '18 at 20:47
|
show 1 more comment
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>
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 :)
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 yourgetName()
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 thanids.size()
and so on the last iteration of theth:each
, you are callinggetName()
on a null object.
– Metroids
Nov 27 '18 at 20:47
|
show 1 more comment
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 :)
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 yourgetName()
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 thanids.size()
and so on the last iteration of theth:each
, you are callinggetName()
on a null object.
– Metroids
Nov 27 '18 at 20:47
|
show 1 more comment
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 :)
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 :)
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 yourgetName()
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 thanids.size()
and so on the last iteration of theth:each
, you are callinggetName()
on a null object.
– Metroids
Nov 27 '18 at 20:47
|
show 1 more comment
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 yourgetName()
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 thanids.size()
and so on the last iteration of theth:each
, you are callinggetName()
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
|
show 1 more comment
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 28 '18 at 15:50
MetroidsMetroids
7,15421226
7,15421226
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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