Add Date Picker to Java JSP

How to Add Java Date Picker

java_jsp_date_picker

Date Picker
Below steps for adding the Date Picker on Java using the Bootstrap and Maven, first add below dependency to the pom.xml

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.0.1</version>
</dependency>

Save or ctrl+s then Maven will download the webjar automatically, you need to restart the webserver either it's an embeded Tomcat or something else so the new dependency gets loaded.

Java Date Picker

The Date Picker is a JavaScript so you need to add the JS to the JSP, to find the Date Picker path, go to left side panel under Maven dependencies and look for the bootstrap datepicker jar, under META-INF\resources\webjars\bootstrap-datepicker....etc "check below Fig#1" , then add the exact path starting from webjars inside the jsp "check Fig#2"

Fig#1
Springdepdency

Fig#2

<script src="webjars/bootstrap-datepicker/1.0.1/js/bootstrap-datepicker.js></script>

 

 

 

JAVA Date Picket Final Step

Next step is to add the date picker to the input box, first check what is the input box name is "Ex. if it's targetDate", then you need to add at the end of the JSP the below script

<script>$('#targetDate').datepicker({
formas : 'dd/mm/yyyy'
});</script>