Estou há um tempão tentando encontrar o erro do parser
do template
, mas não sei como resolver. Em outros formulários utilizo os mesmo comandos e não tive problemas. Alguém pode me ajudar?
Desde já, muito obrigada!
Projeto completo no GitHub.
Recebo essa mensagem na página:
An error happened during template parsing (template: "class path resource [templates/form-hotsite.html]")
Recebo essa exceção no console
, quando tendo acessar a rota: http://localhost:8080/criar-hotsite
:
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "#fields.hasErrors('*')" (template: "form-hotsite" - line 15, col 10)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
... 52 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#fields.hasErrors('*')" (template: "form-hotsite" - line 15, col 10)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:290) ~[thymeleaf-spring5-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:165) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:125) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.processor.StandardIfTagProcessor.isVisible(StandardIfTagProcessor.java:59) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardConditionalVisibilityTagProcessor.doProcess(AbstractStandardConditionalVisibilityTagProcessor.java:61) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.Model.process(Model.java:282) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.Model.process(Model.java:282) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1587) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.Model.process(Model.java:282) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.Model.process(Model.java:290) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.GatheringModelProcessable.process(GatheringModelProcessable.java:78) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleCloseElement(ProcessorTemplateHandler.java:1640) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleCloseElementEnd(TemplateHandlerAdapterMarkupHandler.java:388) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleCloseElementEnd(InlinedOutputExpressionMarkupHandler.java:322) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleCloseElementEnd(OutputExpressionInlinePreProcessorHandler.java:220) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleCloseElementEnd(InlinedOutputExpressionMarkupHandler.java:164) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.attoparser.HtmlElement.handleCloseElementEnd(HtmlElement.java:169) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.HtmlMarkupHandler.handleCloseElementEnd(HtmlMarkupHandler.java:412) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.MarkupEventProcessorHandler.handleCloseElementEnd(MarkupEventProcessorHandler.java:473) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.ParsingElementMarkupUtil.parseCloseElement(ParsingElementMarkupUtil.java:201) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:725) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ~[attoparser-2.0.4.RELEASE.jar:2.0.4.RELEASE]
... 54 common frames omitted
Seguem meus códigos:
Arquivo form-hotsite.html
:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{Layout}">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1 layout:fragment="header">Personalize seu Site</h1>
<div layout:fragment="content">
<div class="alert alert-success" th:if="${globalMessage}" th:text="${globalMessage}">mensagem</div>
<form id="hotsite" th:action="@{/(hotsite)}" th:object="${hotsite}" action="#" method="post">
<p>*Todos os campos são obrigatórios</p>
<div th:if="${#fields.hasErrors('*')}">
<p class="alert alert-danger" role="alert" th:each="error : ${#fields.errors('*')}" th:text="${error}">Erro de validação</p>
</div>
<input type="hidden" th:field="*{id}" th:classappend="${#fields.hasErrors('id')} ? 'field-error'" />
<div class="form-group" >
<label for="pagetitle">Título da Página</label>
<input type="text" class="form-control" id="pagetitle" placeholder="Digite o título da sua página..." th:field="*{pagetitle}" th:classappend="${#fields.hasErrors('pagetitle')} ? 'field-error'" />
</div>
<div class="form-group">
<label for="pagesubtitle">Subtítulo da Página</label>
<input type="text" class="form-control" id="pagesubtitle" placeholder="Digite o subtítulo da sua página..." th:field="*{pagesubtitle}" th:classappend="${#fields.hasErrors('pagesubtitle')} ? 'field-error'" />
</div>
<div class="form-group">
<label for="historytext">Sua história</label>
<textarea class="form-control" id="historytext" rows="3" placeholder="Conte um pouco da sua história..." th:field="*{historytext}" th:classappend="${#fields.hasErrors('historytext')} ? 'field-error'" /></textarea>
</div>
<div class="form-group float-right">
<input class="btn btn-dark" type="submit" value="Enviar" style="background-color:#800080;"/>
<input class="btn btn-dark" type="reset" value="Limpar" style="background-color:#800080;"/>
</div>
</form>
</div>
</body>
</html>
Arquivo HotSite.java
:
package com.hotsitept.models;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
@Entity(name="HotSite")
@Table(name="hotsite")
public class HotSite implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@NotNull
@Column(length=150)
private String pagetitle;
@NotNull
@Column(length=250)
private String pagesubtitle;
@NotNull
@Column(length=1000)
private String historytext;
/*Getters and setters*/
Arquivo HotSiteController.java
:
package com.hotsitept.controllers;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.hotsitept.models.HotSite;
import com.hotsitept.repositories.HotSiteRepository;
@Controller
@RequestMapping("/")
public class HotSiteController {
@Autowired
private HotSiteRepository hotSiteRepository = null;
@GetMapping
public String home() {
return "index";
}
@GetMapping("/criar-hotsite")
public String myHotSite(@ModelAttribute HotSite hotsite) {
return "form-hotsite";
}
@PostMapping(params="hotsite")
public ModelAndView newHotSite(@Valid HotSite hotsite, BindingResult result, RedirectAttributes redirect) {
if(result.hasErrors()) {
return new ModelAndView("criar-hotsite","formHotsiteErros", result.getAllErrors());
}
hotsite = this.hotSiteRepository.save(hotsite);
redirect.addFlashAttribute("globalMessage","HotSite criado com sucesso");
return new ModelAndView("redirect:/" + "criar-hotsite");
}
}
Minha estrutura de pastas: