How can I correctly set the required HTML attribute for an input tag on a TymeLeaf page?

I am new to Spring MVC and completely new to ThymeLeaf .

So, I am working on a web application using TymeLeaf as a viewing technology, and I have to use this jQuery validation plugin : http://jqueryvalidation.org/

Therefore, I used it in the past in JSP pages.

As shown in the documentation: http://jqueryvalidation.org/documentation/

I need to add the required attribute to an input tag that should be populated by the user, something like this:

<input id="cemail" type="email" name="email" required> 

I tried to do this on my TymeLeaf page, as follows:

 <input id="nome" name="nome" type="text" th:value="*{nome}" required></input> 

But now the problem is that I get this error message in the stacktrace console, and the page does not render 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's wrong? How can I correctly set the required HTML attribute for an input tag declared on a ThymeLeaf page?

+7
java-ee html spring-mvc model-view-controller thymeleaf
source share
2 answers

The correct way to declare an attribute required in HTML5 with a thimeleaf is th:required="required" .

Try:

 <input id="nome" name="nome" type="text" th:value="*{nome}" th:required="required"></input> 
+13
source share

Use it:

 <input id="cemail" type="email" name="email" required="true" /> 

The standard Timeleaf dialect can process templates in any mode, but is especially suitable for web-oriented template modes (XHTML and HTML5 of them). In addition to HTML5, it specifically supports the following XHTML specifications: XHTML 1.0 Transitional, XHTML 1.0 Strict, XHTML 1.0 Frameset, and XHTML 1.1.

More details ...: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#what-is-thymeleaf

0
source share

All Articles