darshakshah1988 / gmaps4jsf

Automatically exported from code.google.com/p/gmaps4jsf
0 stars 1 forks source link

MarkerValue of dragged marker include identifier after ValueChangeEvent #143

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When using ui:repeat or c:forEach to create markers, there is no way to 
identify a marker after it has been dragged.

If we create the markers as such;

<ui:repeat var="loc" value="#{dataBean.allLocations}">
  <gmaps4jsf:marker draggable="true" latitude="#{loc.coordLon}" longitude="#{loc.coordLat}" showInformationEvent="click" submitOnValueChange="true" valueChangeListener="#{dataBean.moveMarker}">

    <gmaps4jsf:htmlInformationWindow htmlText="#{loc.locationName}&lt;br/&gt;#{loc.regionName}"/>

  </gmaps4jsf:marker>
</ui:repeat>

The ValueChangeEvent has a method to the get the old value and the new value, 
however the Old Value is always null. The new value is of type MarkerValue, 
which only contains the getter/setter for Latitude and Longitude.

public void moveMarker(ValueChangeEvent e) {
  Logger log = Logger.getLogger(this.getClass().getName()+".moveMarker");
  MarkerValue oldMarker = (MarkerValue)e.getOldValue();
  MarkerValue newMarker = (MarkerValue)e.getNewValue();
        if (oldMarker == null) {
            log.warning("OLD value is null");
        } 
        if (newMarker == null) {
            log.warning("NEW value is null");
        }
        Double lat = Double.valueOf(newMarker.getLatitude());
        Double lon = Double.valueOf(newMarker.getLongitude());
}

It would be nice if we could assign an identifier (EL value expression) to the 
marker such as;

<gmaps4jsf:marker id="#{loc.id}" draggable="true" latitude="#{loc.coordLon}" 
longitude="#{loc.coordLat}" showInformationEvent="click" 
submitOnValueChange="true" valueChangeListener="#{dataBean.moveMarker}">

And then retrieve the identifier from the MarkerValue;

String id = newMarker.getId();
Double lat = Double.valueOf(newMarker.getLatitude());
Double lon = Double.valueOf(newMarker.getLongitude());
dataFacadeEJB.updateLocation(id, lat, lon);

What version of the product are you using?
This was against 1.1.3u3 with JSF 2.0 on Glassfish 3

Many thanks
  Scott.

Original issue reported on code.google.com by det.scot...@gmail.com on 30 Aug 2010 at 6:44

GoogleCodeExporter commented 8 years ago
I've just found the Groups discussion and the following;
http://groups.google.com/group/gmaps4jsf-dev/browse_thread/thread/f5b436fa8e670f
89

So this is the same problem; I didn't realise the backing object was updated 
with Lat/Lon; however it appears as though the longitude of the backing object 
is updated with the old value, not the new value. As I've outlined above, there 
is no way to identify the ValueChangeEvent back to the backing object, and the 
object is updated after the ValueChangeEvent so there is no easy way to persist 
the change.

Original comment by det.scot...@gmail.com on 30 Aug 2010 at 7:15

GoogleCodeExporter commented 8 years ago
You can use the (jsVariable) to differentiate between markers, and inside your 
event listener:

public void moveMarker(ValueChangeEvent event) throws AbortProcessingException {
      MarkerValue value = (MarkerValue) event.getNewValue();
      Marker source = (Marker) event.getSource();
      String markerID= source.getJsVariable();

      // Here use the marker id ...
}

Please use GMaps4JSF 1.1.4 preRelease2 snapshot1 as it contains a major fix for 
event handlers inside ui:repeat:
http://gmaps4jsf.googlecode.com/files/gmaps4jsf-1.1.4-preRelease2-snapshot1.jar 

Original comment by Hazem.sa...@gmail.com on 30 Oct 2010 at 9:18