java - Thymeleaf Error for <input> date with th:pattern -
i'm trying use th:pattern date input form field following thymeleaf template using spring-mvc without luck. else experienced similar thing , has insight or alternative?
i tried 1. hard-coding pattern
<input type="text" th:pattern="mm/dd/yyyy" th:field="*{classdate}"/>
received error:
request processing failed; nested exception org.thymeleaf.exceptions.templateprocessingexception: not parse expression: "mm/dd/yyyy" and 2. setting pattern in java code template use
<input type="date" th:pattern="${classdate_format}" th:field="*{classdate}"/>
received error:
request processing failed; nested exception org.thymeleaf.exceptions.templateprocessingexception: error during execution of processor 'org.thymeleaf.spring3.processor.attr.springinputgeneralfieldattrprocessor'
pattern html5 attribute of input tag.
pattern validates input value using regex. value, inserts pattern attribute should correct regex pattern.
if using thymeleaf's th: prefix, template processor trying find appropriate variable in spiring's model , insert value of attribute. thymeleaf using spring el it's templates.
so first approach incorrect because of using invalid springel expression.
the second solution looks better, type="date" gives want, works not browsers. ${classdate_format} looks correct expression. understand causes second error more code needed.
anyway there reason use th: prefix pattern attribute? needed if want create regex pattern dynamically @ server side. in case regex pattern pretty straightforward, can use attribute without th:. write correct regex case please refer this answer.
Comments
Post a Comment