Search code examples
jspgoogle-mapsspring-roojspx

jspx pass variables


I'm using Spring Roo and jspx to make a system for managing a property investment portfolio.

In my "propertys/show.jspx" file I have embeded a map using the Google Maps API and now I want the post/zip code of the property to be passed into the geocoding method to display the location of the property on the map.

I am relatively new to jsp(x), however I have tried various options such as using the postcode "id" value or using ${property.postcode}/ ${property.getPostcode()} but none of these work. Surely it is possible what I am trying to do, and I've searched for hours online but have struggled to find anything which helps.

here is my code:

   <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:embed="urn:jsptagdir:/WEB-INF/tags/embed" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <page:show id="ps_propertymodule_model_Property" object="${property}" path="/propertys"  z="WKsfPr4ho5x13a9S80pO1Z6yVzU=">
        <table width="100%;">
            <tr>
                <td width="60%">
        <field:display field="propertyNameNumber" id="s_propertymodule_model_Property_propertyNameNumber" object="${property}" z="DRkvOGCjByMk2N7UunO4fD8LJfc="/>
        <field:display field="streetName" id="s_propertymodule_model_Property_streetName" object="${property}" z="caugN9DlFqoZLN+WEKIjaJEQUSI="/>
        <field:display field="townCity" id="s_propertymodule_model_Property_townCity" object="${property}" z="Fp+KSaGrgdbXhRzllkBo9FxmXIM="/>
        <field:display field="county" id="s_propertymodule_model_Property_county" object="${property}" z="mmJB81/8iBFbt+jXICA9q8xCDHw="/>
        <field:display field="postcode" id="s_propertymodule_model_Property_postcode" object="${property}" z="j1qr8EujBkOLnsX1vcgFaPlEWtU="/>
        <br/>
        <br/>
        <field:display date="true" dateTimePattern="${property_datepurchased_date_format}" field="datePurchased" id="s_propertymodule_model_Property_datePurchased" object="${property}" z="B22znN56FtmM/zueTwnOcjNl83k="/>
        <field:display field="pricePaid" id="s_propertymodule_model_Property_pricePaid" object="${property}" z="CQLyDqQhFtqoYfMusAB/XeA+wW0="/>
        <field:display field="stampDuty" id="s_propertymodule_model_Property_stampDuty" object="${property}" z="x7sgRlL8ROhdb9MonWP33N4Ishs="/>
        <field:display field="legalCost" id="s_propertymodule_model_Property_legalCost" object="${property}" z="TH0DgdlKfeFDefSgq+HDVebcxm0="/>
        <field:display field="agentFee" id="s_propertymodule_model_Property_agentFee" object="${property}" z="05bXxWqJcMzgbwtVBHUujPWU7ZA="/>
        <br/>
        <br/>
        <field:display field="area" id="s_propertymodule_model_Property_area" object="${property}" z="Eb5a0xmk5qSFaKZ3BYMGR7lNYw8="/>
        <field:display field="salePrice" id="s_propertymodule_model_Property_salePrice" object="${property}" z="cQHnoPj/QNnb2XwRclq6n4zR+gs="/>
        <field:display field="saleCommission" id="s_propertymodule_model_Property_saleCommission" object="${property}" z="ULPRSdiwV/tk+kS59uyk16TkcoY="/>
        <field:display field="legalExpenses" id="s_propertymodule_model_Property_legalExpenses" object="${property}" z="/a0+xD2IyDttEZpI9zlcOpruOaQ="/>
        <field:display field="comments" id="s_propertymodule_model_Property_comments" object="${property}" z="RDKzYGFdOQUXNcAhV3/JGF8v7V0="/>
        <field:display field="image" id="s_propertymodule_model_Property_image" object="${property}" z="TBQCQkvQcyTDVJQw7l95WI6zt9U="/>
        <field:display field="vacant" id="s_propertymodule_model_Property_vacant" object="${property}" z="03Pa/jpb5PtZRPMAQzLryud0dBs="/>
        <c:set var="post_code" value="${property.postcode}" />
        </td>
            <td>

        <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBQaHw1aSWtIjQzAiriBPC3hvm7Bs1R35U&amp;sensor=false"><jsp:text></jsp:text></script>
    <script type="text/javascript">
        //<![CDATA[ 
            var map;
      function initialize() {

        var mapOptions = {
          zoom: 8,
          center: new google.maps.LatLng(51.10,-0.84),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);

        codeAddress();
      }


      function codeAddress() {

          var address = document.getElementById(address).value;
          geocoder.geocode( { 'address': address}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              map.setCenter(results[0].geometry.location);
              var marker = new google.maps.Marker({
                  map: map,
                  position: results[0].geometry.location
              });
            } else {
              alert('Geocode was not successful for the following reason: ' + status);
            }
          });
        }
          google.maps.event.addDomListener(window, 'load', initialize);
         // ]]> 
            </script>
            <div  id="map_canvas" style="width: 250px; height: 250px"></div>
            </td>
        </tr>
    </table>
  </page:show> 
</div>

If anyone can give me any hints or tips that would be so appreciated, since I really think this is a basic problem and it is really frustrating me not being able to solve it!

Thanks

Steve


Solution

  • If you take a look in the display.tagx, you can see the object values referred to like this:

    <spring:eval expression="object[field]" />
    

    presumably, you should be able to access postcode using this is your jspx:

    <spring:eval expression="property[postcode]" />
    

    For example:

    <script type="text/javascript">
            //<![CDATA[
                var map;
                var post_code = <spring:eval expression="property[postcode]" />;
                ...