Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC - accessing model from jsp/javascript view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC - accessing model from jsp/javascript view

    Hi,

    Apologies for the ignorance - I'm quite new to all the technologies/frameworks etc mentioned below..

    I have a Spring MVC 3 application (running on Google Apps Engine) where the controller populates some data from a database (a list of "Entry" objects) and sends them to the view which is in JSP and also uses some javascript (to generate a google map).

    I need to access the model from a javascript function. How would I go about it? Here's a pseudo-pseudo () code of what I want to do:

    Code:
    // inside a javascript function
    for (Entry : model.entries) {
       x = entry.getCoords.getX();
       y = entry.getCoords.getY();
       ...
       // and then call javascript function
       jsFunction(x, y, ...);
    }
    Hope that makes sense!

    Thanks

  • #2
    jstl stylee

    Code:
    //inside javascript funtion
    <c:if test="${not empty entries}">
         <c:foreach var="entry" items="entries">
              x = <c:out value="${entry.coords.x}"/>;
              y = <c:out value="${entry.coords.y}"/>;
              ...
              // and then call javascript function
              jsFunction(x, y, ...);
    
         </c:foreach>
    </c:if>
    assumes your list of stuff is called entries in the model

    Comment


    • #3
      works thanks!

      Comment

      Working...
      X