Ich versuche, Methoden auf Webkontextobjekte wie #request und #response in meinen Vorlagen in thymeleaf 3.0.3 und Spring Boot 1.5.1 aufzurufen.Probleme beim Aufrufen von Methoden für Webkontextobjekte in thymeleaf-Vorlage
ich immer Fehler wie diese:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Aufruf Methode: Versuchte Methode Methode (java.lang.String) auf null Kontextobjekt zu nennen
hier ist ein Controller:
@Controller
public class Controller {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint", produces = "text/html")
public String customerServiceSignin(Model uiModel, HttpServletRequest request) {
uiModel.addAttribute("attr1", true); // show proper header
uiModel.addAttribute("attr2", false);
return "template";
}
und eine Vorlage:
<html xmlns:th="http://www.thymeleaf.org">
<div>
<div style="...">
<div class="errorblock" th:unless="${#strings.isEmpty(#request.getAttribute('some_attr'))}" th:utext="${#request.getAttribute('some_other_attr')}"></div>
<form name='f' action="action" method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='username' value="" />
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' />
</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="submit" />
</td>
<td><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
</div>
</div>
</html>
Dies ist ein Beispiel, aber wo immer ich das versuche, bekomme ich diese Fehler. Gibt es ein Stück, das ich vermisse?
Das stimmt, aber warum? Die Dokumentation verweist auf #request not #httpServletRequest. –
Es kommt auf die Thymelaft-Version an. In Version 2 scheint es #httpServletRequest zu sein: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#expression-basic-objects und auf Version 3 #request: http: //www.thymeleaf. org/doc/tutorials/3.0/usethymeleaf.html # expression-basic-objects - allerdings behaupten Sie, Sie benutzen thymeleaf 3 bereits, ich bin mir also nicht sicher, was das Problem ist. Vielleicht verwenden Sie eine ältere Version als Sie denken? – eis