-1

I'm a beginner in jsf, i use gmap in jsf to get long lat

    <f:view contentType="text/html">        
        <p:gmap id="gmap" center="41.381542, 2.122893" zoom="15" type="ROADMAP"   
style="width:600px;height:400px"  
model="#{restaurant.emptyModel}"   
onPointClick="handlePointClick(event);"/> </f:view>

How can i show a message that "Please add marker" when user has not added marker. Thank for helping

Do Thanh Tung
  • 1,223
  • 2
  • 19
  • 30
  • 2
    as I see here is good [primefaces example](http://www.primefaces.org/showcase/ui/gmapAddMarkers.jsf), which shows how to add marker and you can save state (added or not) in some variable – Darka Sep 18 '13 at 18:45
  • @Darka: I read it before, but i have only a button "submit"(h:commandButton), and i want show message when clicking button without adding marker. – Do Thanh Tung Sep 18 '13 at 18:50

1 Answers1

0

following example suggested by Darka, You need to place such code in Your button's action method:

public void buttonClick() {
    if (emptyModel.getMarkers().isEmpty()) {
        addMessage(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "You didn't placed a marker!"));
    }
}

public void addMessage(FacesMessage message) {
    FacesContext.getCurrentInstance().addMessage(null, message);
}

Also ensure, that You have added update="messages" attribute to Your button on JSF page.

Short explanation: if user won't place a marker, emptyModel.getMarkers() should return empty list of markers. Then, if it's really empty, You add faces message. Updating growl will provide display of the error message on right upper corner of the page.

Hope this helps. Cheers!

greenskin
  • 544
  • 8
  • 22
  • I added it to my source code, but in `h:commandButton` there is an error like this : `Method must have signature "String method(), String method(), String method(String), String method(String, String), String method(String, String, String), String method(String, String, String, String), String method(String, String, String, String, String), String method(String, String, String, String, String, String), String ...but has signature "void method()"` – Do Thanh Tung Sep 25 '13 at 09:15
  • 1
    Maybe this will help: http://stackoverflow.com/questions/8083469/validation-error-on-valid-facelet-when-calling-action-method-with-parameter – greenskin Sep 25 '13 at 10:00
  • I wan't that error message be displayed as a html text, what should i do? thanks – Do Thanh Tung Sep 25 '13 at 10:55