There was an unexpected error (type=Internal Server Error, status=500). An error happened during template parsing [closed]

I was basically making a E-commerce project using spring boot, thymleaf, html, css. And I am getting and server error while parsing the thymeleaf template which is There was an unexpected error (type=Internal Server Error, status=500). An error happened during template parsing (template: "class path resource [templates/EditProduct.html]")

Here is my controller class:

@GetMapping("/edit")
    public String showEditPage(
            Model model,
            @RequestParam int id
            ) {
        
        try {
            
            Product product = repo.findById(id).get();
            model.addAttribute("product", product);
            
            ProductDto productDto = new ProductDto();
            productDto.setName(product.getName());
            productDto.setBrand(product.getBrand());
            productDto.setCategory(product.getCategory());
            productDto.setPrice(product.getPrice());
            productDto.setDescription(product.getDescription());
            
            model.addAttribute("productDto", productDto);
        }
        catch(Exception ex){
            System.out.println("Execption:  " + ex.getMessage());
            return "redirect:/products";
        }
        
        return "EditProduct";
    } 
    
}

Here is my Parsing template:

<form method="post" enctype="multipart/form-data" th:object="${productDto}">
 <div class="row mb-3">
 <label class="col-sm-4 col-form-label">ID</label>
 <div class="col-sm-8">
 <input readonly class="form-control-plaintext" th:field="${product.id}">
   </div>
   </div>
                                            
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Name</label>
<div class="col-sm-8">
<input class="form-control" th:field="${productDto.name}">
<p th:if="${#fields.hasErrors('name')}" th:errorclass="text-danger th:errors="${productDto.name}"></p>             
</div>
</div>
                                                        
                                                        
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Brand</label>
 <div class="col-sm-8">
 <input class="form-control" th:field="${productDto.brand}">
 <p th:if="${#fields.hasErrors('brand')}" th:errorclass="text-danger" th:errors="${productDto.brand}"></p>
  </div>
  </div>
                                
 <div class="row mb-3">
<label class="col-sm-4 col-form-label">Category</label>
<div class="col-sm-8">
<select class="form-select" th:field="${productDto.category}">
<option value='Motherboard'>Motherboard</option>
<option value='Ram'>Ram</option>
<option value='Graphics Card'>Graphics Card</option>
<option value='Storage'>Storage</option>
<option value='PowerSupplyUnit'>PowerSupplyUnit</option>
<option value='Cabinet'>Cabinet</option>
<option value='Monitor'>Monitor</option>
<option value='Keyboard'>Keyboard</option>
<option value='Mouse'>Mouse</option>
<option value='Gaming Headset'>Gaming Headset</option>
</select>

<p th:if="${#fields.hasErrors('category')}" th:errorclass="text-danger" th:errors="${productDto.category}"></p>
</div>
</div>
                                        
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Price</label>
<div class="col-sm-8">
<input class="form-control" type="number" step="0.01" min="0" th:field="${productDto.price}">
<p th:if="${#fields.hasErrors('price')}" th:errorclass="text-danger" th:errors="${productDto.price}"></p>
</div>
</div>
                                
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Description</label>
<div class="col-sm-8">
<textarea class="form-control" th:field="${productDto.description}"></textarea>
<p th:if="${#fields.hasErrors('description')}" th:errorclass="text-danger"
th:errors="${productDto.description}"></p>
</div>
</div>
                                                
<div class="row mb-3"> 
<div class="offset-sm-4 col-sm-8">
<img th:src="@{'/images/' + ${product.imageFilename}}"
alt="..." width="150">
</div>  
</div>
                                        
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Image</label>
<div class="col-sm-8">
<input class="form-control" type="file"  th:field="${productDto.imageFile}">
<p th:if="${#fields.hasErrors('imageFile')}" th:errorclass="text-danger"
th:errors="${productDto.imageFile}"></p>
</div>
</div>
                                
<div class="row mb-3">
<label class="col-sm-4 col-form-label">Created At</label>
<div class="col-sm-8">
<input readonly class="form-control-plaintext" th:value="${product.createdAt}">     
</div>
</div>      
                                         
<div class="row">
<div class="offset-sm-4 col-sm-4 d-grid">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
<div class="col-sm-4 d-grid">
<a class="btn btn-outline-primary" href="/products" role="button">Cancel</a>
</div>
</div>
                                
</form>
</div>
</div>
                                
        </div>
    </div>  

Here is my html thymleaf template and I am getting the following error:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Jul 18 22:35:50 PDT 2024
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/EditProduct.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/EditProduct.html]")

New contributor

Akshat Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Usually Thymeleaf elaborates the reason of failure, follow the stack trace.
Check if ProductDto has imageFile field and Product has createdAt, imageFilename. And, as mentioned above, fix the line 12.

I tried the snippet and it shows the page after these exercises. But the issue could be outside the <form> block

New contributor

lo-fi wi-fi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật