I am trying to call methods on web context objects such as #request and #response in my templates in thymeleaf 3.0.3 and Spring Boot 1.5.1.
I continually get errors like this:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method method(java.lang.String) on null context object
Here is a 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";
}
and a template:
<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>
This is one example, but anywhere I attempt to do this I get these errors. Is there a piece I am missing?
Turns out #request needed to be #httpServletRequest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With