views:

177

answers:

4

I'm using GMaps4JSF 1.1.3-u3 in a JavaEE 6 Application with JSF 2.0, Facelets, Mojarra 2.0.2 and Primefaces 2.1 on a Glassfish v3 app server. On a xhtml page i want to show some Markers and a moveable Marker (the current selected "station"). Its longitude and latitude positions are stored in some variables with the help of the valueChangeListener. When i use the confirmButton the postion is saved to a station object. Then all stations are reloaded and the form is updated. When i select the station its new position is displayed on the map - everything works. If i move the marker and press the cancelButton and afterwards select the same station in the table, the position of this moving is displayed although the cancelOperation restores the old position (stationLongitude and stationLatitude variables). Thats necessary because the valueChangeListener is called before the cancel Function. I have tried many things but i'm not able to perform the cancelation so that after reselecting the concerned station the old marker position is displayed. It only works when i use oncomplete="window.location.reload()" on the ajax cancelButton! But this leads to ugly page update (first ajax updates then whole page is reloaded). I'm not sure if this is a GoogleMaps, GMaps4JSF or Facelets problem or something else. Maybe there is a good workaround or i've just done something wrong! Maybe its possible to refresh the Marker position or the marker has an internal state? I'm interested in any hint! Thanks in advance!

The XHTML Snippet:

     <h:form prependId="false" id="xTableForm">
        <div class="xSection" >
            <p:dataTable id="xTable" var="station" value="#{XBean.stations}" 
                selection="#{XBean.selectedStation}" selectionMode="single"
                update="xTableForm pMessages">
                ...
            </p:dataTable>
        </div>

        <h:panelGrid id="mapPanelGrid">
            <m:map width="929px" height="500px"  
            longitude="#{XBean.stationLongitude}" latitude="#{XBean.stationLatitude}" 
            renderOnWindowLoad="false">
                <ui:repeat ... >
                    ... other markers
                </ui:repeat>
                <m:marker id="stationMarker" longitude="#{XBean.stationLongitude}" 
                    latitude="#{XBean.stationLatitude}" jsVariable="sMarker" draggable="true"
                    submitOnValueChange="false" valueChangeListener="#{XBean.valueChangeListener}" >
                    <m:icon imageURL="http://www.google.com/mapfiles/marker_blackS.png"/&gt;
                </m:marker>
                <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_RIGHT"/>
                <m:mapControl name="GMapTypeControl"/>
            </m:map>
        </h:panelGrid>

        <div id="xMenu">
            ...
            <p:commandLink id="confirmButton" value="confirm"
                actionListener="#{XBean.confirm}" update="XTableForm pMessages" />
            <p:commandLink id="cancelButton" value="Cancel"
                actionListener="#{XBean.cancelOperation}" update="XTableForm pMessages" />
        </div>
    </h:form>
A: 

Maybe you can use PrimeFaces's draggable markers;

http://www.primefaces.org/showcase/ui/gmapDraggableMarkers.jsf

Cagatay Civici
Thats nice. As soon as i have some time i'll try it...
Michael W.
A: 

What is the code behind (#{XBean.cancelOperation}[1])?
It will be nice to send us a sample war with the problem so we can help you[2].
[1] I expect to set the default marker positions in the reset action.
[2] http://groups.google.com/group/gmaps4jsf-dev

Hazem Ahmed Saleh
Thank you! [1] the cancelOperation Method sets XBean.stationLongitude and XBean.stationLatitude to the previous values (before the marker was moved). [2] Your example reproduces exactly the issue.
Michael W.
A: 

I added an example of your case: http://www.mashups4jsf.com/gmaps4jsf-test/pages/markersServerSideEvents2.jsf

Wish it helps!

Hazem Ahmed Saleh
Thanks! This example reproduces the problem. [Case 1] You move the marker and save, then you hit the reset button > the marker is reseted to its default position.[Case 2] You move the marker and perform no saving, then hit the reset button > the marker is not reseted to its default position > you hit the reset button a second time > the marker is reseted to its default position. [Case 2] Is exactly the problem.
Michael W.
Now I got what you mean. This is a defect. I will provide a fix soon:http://code.google.com/p/gmaps4jsf/issues/detail?id=139
Hazem Ahmed Saleh
Okay that's good. Thanks Hazem!
Michael W.
A: 

I had the same issue. I have fixed it with folloiwng code:

private void rebuildRootView() { FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); ViewHandler viewHandler = application.getViewHandler(); UIViewRoot viewRoot = viewHandler.createView(context, context.getViewRoot().getViewId()); context.setViewRoot(viewRoot); }

I call this method in cancelButton listener

Alex
I do not understand why but your solution works. Thank you!
Michael W.
But only if i use p:commandLink without ajax.
Michael W.