Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:59:44+00:00 2026-05-23T04:59:44+00:00

I use the google map tool from primefaces . I want my user to

  • 0

I use the google map tool from primefaces.
I want my user to be able to place just one marker on a map.
The values of the coordinates should be stored in a managed bean variables.

How can I do that?
See what I did so far:

I created the map:

    <f:view contentType="text/html">
            <p:gmap id="gmap" center="36.890257,30.707417" zoom="13" type="HYBRID"   
    style="width:600px;height:400px"  
    model="#{mapBean.emptyModel}"   
    onPointClick="handlePointClick(event);"   
    widgetVar="map" />  </f:view>

<p:dialog widgetVar="dlg" effect="FADE" effectDuration="0.5" close="false" fixedCenter="true">  
    <h:form prependId="false">  
        <h:panelGrid columns="2">  
            <h:outputLabel for="title" value="Title:" />  
            <p:inputText id="title" value="#{mapBean.title}" />  

            <f:facet name="footer">  
                <p:commandButton value="Add"   
                        actionListener="#{mapBean.addMarker}"   
                        update="messages"   
                        oncomplete="markerAddComplete()"/>  
                <p:commandButton value="Cancel" onclick="return cancel()"/>  
            </f:facet>  
        </h:panelGrid>  

        <h:inputHidden id="lat" value="#{newOfferSupportController.mapLocationX}" />  
        <h:inputHidden id="lng" value="#{newOfferSupportController.mapLocationY}" />  
    </h:form>  
</p:dialog>  

<script type="text/javascript">  
    var currentMarker = null;  

    function handlePointClick(event) {  
        if(currentMarker == null) {  
            document.getElementById('lat').value = event.latLng.lat();  
            document.getElementById('lng').value = event.latLng.lng();  

            currentMarker = new google.maps.Marker({  
                position:new google.maps.LatLng(event.latLng.lat(), event.latLng.lng())  
            });  

            map.addOverlay(currentMarker);  

            dlg.show();  
        }     
    }  

    function markerAddComplete() {  
        var title = document.getElementById('title');  
        currentMarker.setTitle(title.value);  
        title.value = "";  

        currentMarker = null;  
        dlg.hide();  
    }  

    function cancel() {  
        dlg.hide();  
        currentMarker.setMap(null);  
        currentMarker = null;  

        return false;  
    }  
</script>

I also greated the variables that will hold the coordinates:

@ManagedBean
@RequestScoped
public class NewOfferSupportController {

private float mapLocationX;
private float mapLocationY;

//Get & set methods

It all works as in the primefaces page but I have 2 problems:

Problem 1: Once the marker is placed, it cannot be placed again.

Problem 2: In the same form where the map is there are some other elements such as text fields. I noticed that validation does not occur when I click on the submit button located in the form where the map is, Actually the form does not get submitted at all(This didn’t occur before i added the map), why is the map disrupting the validation?
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:59:44+00:00Added an answer on May 23, 2026 at 4:59 am

    Problem 1: Once the marker is placed, it cannot be placed again.

    This problem is caused by the following things:

    1. You’ve bound latitude and longitude to a different bean (NewOfferSupportController) than the bean which holds the map model (MapBean). You should be using MapBean example in the PrimeFaces showcase as design starting point for NewOfferSupportController bean. It namely stores the markers set. The hidden inputs must point to that bean because in the addMarker() method those values will be added. From the showcase example you just have to rename the MapBean class name and rename #{mapBean} references in the view by #{newOfferSupportController}.

    2. Your NewOfferSupportController bean is request scoped while it should be view scoped.

      @ManagedBean
      @ViewScoped
      public class NewOfferSupportController implements Serializable {}
      

      View scoped beans live as long as you’re interacting with the same form by Ajax. But request scoped beans get recreated on every request (and thus also on every Ajax request!), hereby trashing the markers which are placed before in the map and inputs which are entered before adding markers.


    Problem 2: In the same form where the map is there are some other elements such as text fields. Actually the form does not get submitted at all(This didn’t occur before i added the map), why is the map disrupting the validation?

    This works for me. This is likely caused because your NewOfferSupportController is been placed in the request scope instead of the view scope.

    To recap, here is the code which I used in my test:

    view:

    <p:growl id="messages" showDetail="true" />  
    
    <h:form>
        <p:gmap id="gmap" center="36.890257,30.707417" zoom="13" type="HYBRID" style="width:600px;height:400px"  
            model="#{mapBean.mapModel}" onPointClick="handlePointClick(event);" widgetVar="map" />
        <h:inputText value="#{mapBean.input}" required="true" />
        <p:commandButton value="submit" action="#{mapBean.submit}" update="messages" />
    </h:form>
    
    <p:dialog widgetVar="dlg" effect="FADE" effectDuration="0.5" close="false" fixedCenter="true">  
        <h:form prependId="false">  
            <h:panelGrid columns="2">  
                <h:outputLabel for="title" value="Title:" />  
                <p:inputText id="title" value="#{mapBean.title}" />  
    
                <f:facet name="footer">  
                    <p:commandButton value="Add" actionListener="#{mapBean.addMarker}"   
                        update="messages" oncomplete="markerAddComplete()"/>  
                    <p:commandButton value="Cancel" onclick="return cancel()"/>  
                </f:facet>
            </h:panelGrid>
    
            <h:inputHidden id="lat" value="#{mapBean.lat}" />  
            <h:inputHidden id="lng" value="#{mapBean.lng}" />
        </h:form>  
    </p:dialog>  
    

    (I didn’t change the <script> code in the showcase example, just add it unchanged)

    Bean:

    @ManagedBean
    @ViewScoped
    public class MapBean implements Serializable {  
    
        private MapModel mapModel;  
        private String title;  
        private double lat;  
        private double lng;  
        private String input;
    
        public MapBean() {  
            mapModel = new DefaultMapModel();  
        }  
    
        public void addMarker(ActionEvent actionEvent) {  
            mapModel.addOverlay(new Marker(new LatLng(lat, lng), title));  
            addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Marker Added", "Lat:" + lat + ", Lng:" + lng));  
        }  
    
        public void submit() {
            addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Form submitted", "Amount markers: " + mapModel.getMarkers().size() + ", Input: " + input));
        }
    
        public void addMessage(FacesMessage message) {  
            FacesContext.getCurrentInstance().addMessage(null, message);  
        }  
    
        // Getters+setters.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As we all know, how to use google map with system/framework/map.jar with user-library .
I want to use Google spreadsheets to store data online so multiple people can
I want to use google chrome as a control. I think Enso does this
I'm trying to use a Google Map as a background, with a fixed overlay.
I have a page which shows a Google map. I'd like to use Javascript
is it possible to limit Google map v3 to a certain area? I want
I really hope someone can advise on displaying a google map from a hidden
I want to figure out how Google Map's API to give us directions. Create
Does any have nay information on usage of google map in busines/commerceial use? Is
I'm trying to use Google geocoder service to get the coordinates of cities input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.