darshakshah1988 / gmaps4jsf

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

valueChangeListener is called for all markers in ui:repeat loop when moving one marker. #138

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I found a problem with when using the ui:repeat function and the 
valueChangeListener.

When a repeat loop is used with markers with a valueChangeSubmit and the marker 
is moved for all the markers in the loop the valueChangeSubmit function is 
called with the markervalue of the marker that was moved.

Following code:

   <h:form id="form">
            <m:map id="gmap" width="500px" height="500px" type="G_NORMAL_MAP" address="Breda, NL" >
                <ui:repeat  id="makerloop" value="#{UsersLocationsHandler.allLocationUsers}" var="user">
                    <m:marker  draggable="true" latitude="#{user.latitude}" longitude="#{user.longitude}"  jsVariable="#{user.userid}" submitOnValueChange="true" valueChangeListener="#{UsersLocationsHandler.update}">
                   </m:marker>
                </ui:repeat>
            </m:map>
        </h:form>

  public void update(ValueChangeEvent event) throws AbortProcessingException {
        MarkerValue value = (MarkerValue) event.getNewValue();
        Marker source = (Marker) event.getSource();
        String userid = source.getJsVariable();
        if (userid != null) {
            Users user = users.get(userid);
            if (users != null) {
                users.setLongitude (value.getLatitude());
                users.setLatitude (value.getLongitude());
            }
        }
    }

festivallocatie returns a list with users Beans.

Expected output:
After you moved the marker the function ‘update‘ is called on 
‘UsersLocationsHandler’ This the update must only be called for the marker 
that is moved. (Using the JsVariable I can see what marker is moved.)

I see instead:
    The function update is called for all markers in the loop with the MarkerValue of the marker that is moved.

I am using version 1.1.3u3 on Sailfinv1 with com.sun.facelets.jsf-facelets 
1.1.14

Possible fix:

The decodeMarker function uses the id of the marker. But javascript uses the 
getUniqueMarkerId(). Can be that in de loop the markes all have the same id.

By change the code in MarkerRenderer.decodeMarker to use the 
getUniqueMarkerId() call it works.

New code:

    private void decodeMarker(FacesContext context, Marker marker, String mapState) {

        if (mapState != null && mapState.indexOf(MarkerEncoder.getUniqueMarkerId(context,marker)) != -1) {
            int         start       = mapState.indexOf(MarkerEncoder.getUniqueMarkerId(context,marker) + "=");
            int         end         = mapState.indexOf(")", start);
            String      markerState = mapState.substring(start, end + 1);
            MarkerValue markerValue = getMarkerValueFromState(markerState);

            marker.setSubmittedValue(markerValue);
        }
    }

Hoop you can fix it in a new version.

Greetings
Corné

Original issue reported on code.google.com by kipk...@gmail.com on 20 Aug 2010 at 9:48

GoogleCodeExporter commented 8 years ago
We will fix it.
Thanks much.

Original comment by Hazem.sa...@gmail.com on 21 Aug 2010 at 12:16

GoogleCodeExporter commented 8 years ago
will be fixed in 1.1.4.

Original comment by Hazem.sa...@gmail.com on 21 Aug 2010 at 2:29

GoogleCodeExporter commented 8 years ago
MUST BE FIXED BEFORE 1.1.4 RELEASE.

Original comment by Hazem.sa...@gmail.com on 21 Aug 2010 at 4:14

GoogleCodeExporter commented 8 years ago
This is the most interesting bug I ever see in GMaps4JSF.

Thanks for detecting it and proposing a fix.

Original comment by Hazem.sa...@gmail.com on 27 Aug 2010 at 10:40

GoogleCodeExporter commented 8 years ago
Issue 140 has been merged into this issue.

Original comment by Hazem.sa...@gmail.com on 28 Aug 2010 at 12:59

GoogleCodeExporter commented 8 years ago
It is fixed in GMaps4JSF 1.1.4 preRelease jar:
http://gmaps4jsf.googlecode.com/files/gmaps4jsf-1.1.4-preRelease1.jar

Please use this jar.

Thanks much for reporting this issue.

Original comment by Hazem.sa...@gmail.com on 28 Aug 2010 at 1:00