How can I add "required" attribute in Spring-MVC?
I want the ending tag to look like this
<input type="text" name="usrname" required>
So I am doing the following in my JSP
<form:input path="usrname" maxlength="12" required/>
But I am gettng a error
The correct way to declare the required attribute in HTML5 with thymeleaf is th:required="required" . Show activity on this post. The Thymeleaf Standard Dialect can process templates in any mode, but is especially suited for web-oriented template modes (XHTML and HTML5 ones).
The Spring MVC framework provides us with standard predefined validators to validate user input data in a simple and straightforward way. The Bean Validation API is the popular approach for data validations in Spring applications.
Spring tag Library The 'form' tag renders an HTML 'form' tag. It exposes a binding path to inner tags for binding the data entered. It puts the command object in the PageContext so that the command object can be accessed by all the inner tags.
I found the fix. my code had to me like this
<form:input path="usrname" maxlength="12" required="required"/>
Now it works.. :)
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