I am pretty new in Spring MVC and absolutly new in ThymeLeaf.
So I am working on a web application that use TymeLeaf as view technology and I have to use this Jquery Validation Plugin: http://jqueryvalidation.org/
So I have used it in the past into JSP pages.
As shown in the documentation: http://jqueryvalidation.org/documentation/
I have to add the required attribute to my input tag that have to be fill by the user, something like this:
<input id="cemail" type="email" name="email" required>
I tryied to do this thing into my TymeLeaf HTML page, in this way:
<input id="nome" name="nome" type="text" th:value="*{nome}" required></input>
But the problem is now I obtain this error message in the stacktrace console and the page is not renderd:
15:36:47,180 ERROR [org.thymeleaf.templateparser.ErrorHandler] (http-localhost/127.0.0.1:8080-3) [THYMELEAF][http-localhost/127.0.0.1:8080-3] Fatal error during parsing: org.xml.sax.SAXParseException; lineNumber: 88; columnNumber: 78; Attribute name "required" associated with an element type "input" must be followed by the ' = ' character.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:175)
Why? What is wrong? How can I correctly set the required HTML attribute to an input tag declated into a ThymeLeaf page?
Use it:
<input id="cemail" type="email" name="email" required="true" />
The Thymeleaf Standard Dialect can process templates in any mode, but is especially suited for web-oriented template modes (XHTML and HTML5 ones). Besides HTML5, it specifically supports and validates the following XHTML specifications: XHTML 1.0 Transitional, XHTML 1.0 Strict, XHTML 1.0 Frameset, and XHTML 1.1.
See More On : http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#what-is-thymeleaf
The correct way to declare the required attribute in HTML5 with thymeleaf is th:required="required"
.
Try:
<input id="nome" name="nome" type="text" th:value="*{nome}" th:required="required"></input>
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