tarexgg
tarexgg

Reputation: 152

Thymeleaf template parsing error

I get parsing error when I try to load localhost:8080/.

I can't find any errors in my template, so why have I this mistake?

Error

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Apr 20 16:59:56 EEST 2015
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="index", line 26 - column 3

Template (HTML)

<tr th:each="customer : ${customers}">
    <td th:text="${customer.identity}">001</td>
    <td th:text="${customer.name}">Name</td>
    <td th:text="${customer.address}">Address</td>
    <td th:text="${customer.age}">Age</td>
</tr>

View (Class)

public String mainPage(Model model){
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    PersonJDBCTemplate personJDBCTemplate = (PersonJDBCTemplate) context.getBean("personJDBCTemplate");
    List<Person> persons = personJDBCTemplate.getAllPersons();
    model.addAttribute("customers", persons);
    return "index";
}

Upvotes: 11

Views: 40273

Answers (2)

Brian Risk
Brian Risk

Reputation: 1449

Your template name may be misspelled!

This just bit me in the butt. All closing tags were verified via online tool, but that won't help you when the template engine name you define in your controller doesn't exactly match with the actual file name.

Note that this answer addresses a possible, but not highly probable explanation for the error. It is more for people coming in from search; the specific reasons that lead the OP to post are most likely caused by the lack of closing tag. However, who knows? The controller code was not included.

Upvotes: 0

Faraj Farook
Faraj Farook

Reputation: 14875

May be you are missing a closing tag somewhere. I have no idea what you have in the HTML template, unless you post the complete code.

But replace your current file with this template. And it should work. Then you can add your missing codes to it.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en"></head>
<body>
<tr th:each="customer : ${customers}">
    <td th:text="${customer.identity}">001</td>
    <td th:text="${customer.name}">Name</td>
    <td th:text="${customer.address}">Address</td>
    <td th:text="${customer.age}">Age</td>
</tr>
</body>
</html>

Upvotes: 17

Related Questions