title: How can I get geocoder address to backing bean?
body: <p>Using PrimeFaces p:gmap component.</p>
  
  <p>I have a page with a gmap component with a set of markers.<br>
  I want to display the street address in the gmapInfoWindow and pass it to the backing bean as well.
  When I click on the map marker, I call a javascript function to get the reverse geocoder address.
  I can fetch the address and display it in a javascript alert dialog, but I can't get it to fill the backing bean variable or in the info marker.</p>
  
  <p>The variable does get filled, but it does not get updated until the next time I click on the marker.
  As a result, the addresses are always one marker click behind.</p>
  
  <p>Does anyone know how I can get the address to update during the current page session?
  Thanks.</p>
  
  <p>The backing bean code onMapMarkerSelect just has a System.out.println statement to show the mapAddress variable.<br>
  Here is the page code:</p>
  
  <pre><code>                &lt;h:form prependId="false" &gt;
                       &lt;p:gmap id="gmap" center="#{mappingSessionBean.mapCenter}" zoom="#{mappingSessionBean.mapZoom}" type="HYBRID" rendered="true"
                              style="#{mappingSessionBean.polygonGmapStyle}" onPointClick="handlePointClick(event);"
                              model="#{mappingSessionBean.mapModel}" fitBounds="#{mappingSessionBean.fitBoundsFlag}"
                              widgetVar="map" &gt;
                          &lt;p:ajax id="gmapAjax" event="overlaySelect" immediate="true" onstart="handlePointClick(event);" listener="#{mappingSessionBean.onMapMarkerSelect}" /&gt;
                          &lt;p:gmapInfoWindow id="infoWindow" &gt;
                              &lt;p:outputPanel &gt;
                                  &lt;h:panelGrid columns="1" &gt;
                                      &lt;h:outputText id="infoWindowTitle" value="#{mappingSessionBean.selectedMarker.title}" /&gt;
                                      &lt;h:outputText id="infoWindowAddress" value="#{mappingSessionBean.mapAddress}" rendered="true" /&gt;
                                      &lt;p:commandButton value="Zoom In" action="#{mappingSessionBean.selectedViewInfoListener}" update="gmap" /&gt;
                                  &lt;/h:panelGrid&gt;
                              &lt;/p:outputPanel&gt;
                          &lt;/p:gmapInfoWindow&gt;
                      &lt;/p:gmap&gt;
                      &lt;h:inputHidden id="address" value="#{mappingSessionBean.mapAddress}" /&gt;
                  &lt;/h:form &gt;
  
          &lt;script type="text/javascript" &gt;
              function handlePointClick(event) {
                  if(navigator.geolocation)
                  {
                      browserSupportFlag = true;
                      var latlng = event.latLng;
                      geocoder = new google.maps.Geocoder();
                      geocoder.geocode({'latLng': latlng}, function(results, status)
                      {
                          if( status == google.maps.GeocoderStatus.OK )
                          {
                              alert( results[0].formatted_address );
                              document.getElementById('address').value = results[0].formatted_address;
                              document.getElementById('infoWindowAddress').value = results[0].formatted_address;
                          }
                          else
                          {
                              alert( "Geocoder failed due to: " + status );
                          }
                      });
                  }
                  else
                  {
                      alert( "No Geolocation");
                  }
              }
          &lt;/script&gt;
  </code></pre>