Pergunta

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"/>
                </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>
Foi útil?

Solução

I had the same issue. I have fixed it with the following 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.

Outras dicas

Maybe you can use PrimeFaces's draggable markers;

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

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top