I’ve got a Spring Web MVC application where I need to get a JavaScript Array filled with java.util.Dates that are stored in an ArrayList accessible from the webapp with ${cust.dates}.
How do I properly initialize the array in the webapp?
Thank you.
Spring executes at server-side, and JavaScript executes at client-side. For the point of view of Spring, JavaScript is just text that must be generated. And this text must represent valid JavaScript source code.
The JavaScript source code that creates an array of dates could thus be generated like this:
This will generate the following JavaScript code:
with the numeric arguments being the number of milliseconds since the epoch, which is the same in Java and JavaScript.