Tuesday, February 9, 2016

Accessing JSP data inside JavaScript or jQuery

Issue: I came across this situation while trying to add row of select boxes to a table in a JSP page upon clicking an AddRow button. The 'select' boxes should be populated with some model data(jsp data) received from Spring's controller. I am able to add the row of select boxes to the table using jQuery but unable to use the JSP data to the select boxes.

Solution: After searching various solutions on internet, I finalized on 2 methods:

Method 1: Set the JSP data to a html element and read the data inside jQuery and use it.
Method 2: Go for ajax calls in jQuery to fetch data from controller every time you need to populate the select boxes.

No comments:

How J2EE components work together in any Container - Spring or Application Server

In a Spring+Jersey+Hibernate RESTful webapplication, we can spot various J2EE components - JTA, JPA, Java Bean Validation, JSON-B API for B...