Gmap refresh if user click on a jsf dropdown menue
y0da Jun 18, 2007 4:42 AMHi!
Always if i wanna choose a value from a dropdownmenu (which on the same jsp as the gmap) the map get refreshed - furthermore i just have 2 seconds to choose a value from the dropdown - if im to slow i must reclick on the dropdown because the map refresh close the dropdown. it is really weird because the dropdown menue hasnt a valuechangelistener or post back to form..it just the setMap method get called..
the jsp:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%> <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%> <html> <head> <title>gathering place detail</title> <link rel="stylesheet" type="text/css" href="../css/agr.css" /> <script type="text/javascript" src="../script/block.js"></script> <script type="text/javascript" src="../script/default.js"></script> <script type="text/javascript"> //<![CDATA[ function createPoint(data) { var point = new GLatLng(data.lat, data.lng); map.addOverlay(createMarkerWithIdentifier(point, data.desc)); } function createPoints(data) { for (var i = 0; data.length; i++) { var point = new GLatLng(data.lat, data.lng); map.addOverlay(createMarkerWithIdentifier(point, data.desc)); } } function createMarkerWithIdentifier(point, desc) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(desc); }); return marker; } //]]> </script> </head> <body> <f:view> <f:loadBundle basename="bundles.labels" var="labels" /> <h:form id="placeDetail"> <table> <TR> <TD> <h:outputText value="#{labels.masterData}:" styleClass="txtgruen"/> <h:panelGrid columns="2" columnClasses="table_left, table_right" styleClass="table"> <h:outputText value="#{labels.district}:" styleClass="bold"/> <h:outputText value="#{placeDetail.district}" styleClass="txtklein"/> <h:outputText value="#{labels.locality}:" styleClass="bold"/> <h:outputText value="#{placeDetail.locality}" styleClass="txtklein"/> <h:outputText value="#{labels.zip}:" styleClass="bold"/> <h:outputText value="#{placeDetail.zip}" styleClass="txtklein"/> <h:outputText value="#{labels.collectorLocation}:" styleClass="bold"/> <h:outputText value="#{placeDetail.collectorLocaltity}" styleClass="txtklein"/> <h:outputText value="#{labels.address}:" styleClass="bold"/> <h:outputText value="#{placeDetail.address}" styleClass="txtklein"/> </h:panelGrid> </TD> </TR> </TR> <TR></TR><TR></TR><TR></TR><TR></TR> <TD> <h:outputText value="#{labels.caseData}:" styleClass="txtgruen"/> <t:dataTable id="pivotAttrData" value="#{placeDetail.caseData}" var="element" preserveDataModel="false" headerClass="header" headerClass="header" styleClass="table" rows="10" binding="#{placeDetail.caseDataDataTable}"> <t:column id="caseTypeId"> <f:facet name="header"> <h:outputText value="#{labels.caseType}" styleClass="bold"/> </f:facet> <h:outputText value="#{element.caseType}"styleClass="txtklein"/> </t:column> <t:column id="countId"> <f:facet name="header"> <h:outputText value="#{labels.count}" styleClass="bold"/> </f:facet> <h:outputText value="#{element.count}" styleClass="txtklein"/> </t:column> <t:column id="qualityOfGlassKindId"> <f:facet name="header"> <h:outputText value="#{labels.qualityOfGlassKind}" styleClass="bold"/> </f:facet> <h:outputText value="#{element.qualityOfGlassKind}" styleClass="txtklein"/> </t:column> </t:dataTable> </TD> </TR> <TR></TR><TR></TR><TR></TR><TR></TR> <TR> <TD> <h:panelGrid> <rich:gmap binding="#{gmBean.map}"/> </h:panelGrid> </TD> </TR> <TR> <TD> <h:outputText value="#{labels.requestData}:" styleClass="txtgruen"/> <h:panelGrid columns="2" columnClasses="table_left, table_right" styleClass="table"> <h:outputText value="#{labels.type}" styleClass="bold"/> <h:selectOneMenu value="#{placeDetail.dropDownSelected}" styleClass="dropdown" onclick="return DoPostBack('placeDetail');" binding="#{placeDetail.dropDown}"> <f:selectItems value="#{placeDetail.dropDownPossibles}" /> </h:selectOneMenu> <h:outputText value="#{labels.title}" styleClass="bold"/> <h:inputText value="#{placeDetail.title}" styleClass="txtklein"/> <h:outputText value="#{labels.forename}" styleClass="bold"/> <h:inputText value="#{placeDetail.forename}" styleClass="txtklein"/> <h:outputText value="#{labels.surname}" styleClass="bold"/> <h:inputText value="#{placeDetail.surname}" styleClass="txtklein"/> <h:outputText value="#{labels.emailFrom}" styleClass="bold"/> <h:inputText value="#{placeDetail.emailFrom}" styleClass="txtklein"/> <h:outputText value="#{labels.callNumber}" styleClass="bold"/> <h:inputText value="#{placeDetail.callNumber}" styleClass="txtklein"/> <h:outputText value="#{labels.locality}" styleClass="bold"/> <h:inputText value="#{placeDetail.localityF}" styleClass="txtklein"/> <h:outputText value="#{labels.zip}" styleClass="bold"/> <h:inputText value="#{placeDetail.zipF}" styleClass="txtklein"/> <h:outputText value="#{labels.message}" styleClass="bold"/> <h:inputTextarea value="#{placeDetail.message}" styleClass="txtklein" cols="64" rows="4"/> <f:verbatim><BR/></f:verbatim> <h:commandButton id="submitId" value="#{labels.submit}" actionListener="#{placeDetail.doInsert}"/> </h:panelGrid> </TD> </TR> </table> <a4j:jsFunction name="initializePoints" data="#{gmBean.point}" oncomplete="createPoint(data)"> </a4j:jsFunction> </h:form> </f:view> </body> </html>
gmap bean:
package at.pcd.wam.technologie.controller; import java.util.ArrayList; import java.util.HashMap; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import org.richfaces.component.html.HtmlGmap; import at.pcd.wam.technologie.controller.model.MapData; public class GoogleMapController { //------------------------------------------------------------------------------------------------------------------ // FIELDS //------------------------------------------------------------------------------------------------------------------ /** google map */ private HtmlGmap map; /** whole authorization for google map */ private String gmapKey; /** google key for localhost - http://localhost:8080/ */ private static final String GOOGLE_API_KEY = "ABQIAAAAU5IDceLqYFSp4k84FYLxyRTwM0brOpm-All5BF6PoaKBxRWWERSDiAIGyx-hbmMfA3v7tHF4Tvwfaw"; /** application url for localhost */ private static final String APPL_URL = "localhost:8080"; /** host string */ private static final String HOST = "host"; /** error message if key is not generated for <code>Bean.APPL_URL</code> */ private static final String KEY_ERROR_MSG = "get the key for your domain at http://www.google.com/apis/maps/signup.html"; /** style of the google map */ private static final String MAP_STYLE = "width:250px;height:400px"; /** java script method which load points for google map - ajax4jsf script */ private static final String LOAD_POINTS_INITIALIZE = "initializePoints()"; /** google map initial zoom */ private static final String MAP_ZOOM_INITIAL = "15"; /** google map initial type of show value */ private static final String MAP_TYPE_INITIAL = "G_NORMAL_MAP"; /** google map variable for java script */ private static final String MAP_GMAP_VAR = "map"; /** contains google map points data */ private ArrayList<MapData> points; /** contains google map point data */ private MapData point; /** point x */ private String pointX; /** point y */ private String pointY; private Boolean refresh = false; //------------------------------------------------------------------------------------------------------------------ // CONSTRUCTOR //------------------------------------------------------------------------------------------------------------------ /** * empty constructor */ public GoogleMapController() { // nothing to do } //------------------------------------------------------------------------------------------------------------------ // HELPER METHODS //------------------------------------------------------------------------------------------------------------------ /** * set point to google map * * @param desc * desc * @param geoX * geoX * @param geoY * geoY */ public void addPoint2Map(final String geoX, final String geoY, final String desc) { this.setPoint(new MapData(geoX, geoY, desc)); } /** * create the whole google map key * * @return key generated key */ private String createKey() { HashMap<String, String> hosts = new HashMap<String, String>(); hosts.put(GoogleMapController.APPL_URL, GoogleMapController.GOOGLE_API_KEY); ExternalContext ec = FacesContext.getCurrentInstance() .getExternalContext(); String host = (String) ec.getRequestHeaderMap().get( GoogleMapController.HOST); String key = hosts.get(host); if (key != null) { return key; } else { return GoogleMapController.KEY_ERROR_MSG; } } //------------------------------------------------------------------------------------------------------------------ // GETTER/SETTER //------------------------------------------------------------------------------------------------------------------ /** * getter method * * @return points google map points */ public ArrayList<MapData> getPoints() { return this.points; } /** * setter method * * @param points * google map points */ public void setPoints(final ArrayList<MapData> points) { this.points = points; } /** * getter method * * @return gmapKey */ public String getGmapKey() { if (this.gmapKey == null) { this.gmapKey = this.createKey(); } return this.gmapKey; } /** * setter method * * @param gmapKey * google map key */ public void setGmapKey(final String gmapKey) { this.gmapKey = gmapKey; } /** * getter method * * @return map */ public HtmlGmap getMap() { return this.map; } /** * set the correct coordinates for the point - map will center this point * then * * @param lattidude * lattidude value for map to focus point * @param longtitude * longtitude value for map to focus point */ public void centerMap2Point(final String longtitude, final String lattidude) { this.pointX = longtitude; this.pointY = lattidude; } /** * setter method also initialized google map * * @param map * google map */ public void setMap(final HtmlGmap map) { if (this.map == null) { this.map = map; this.map.setGmapVar(GoogleMapController.MAP_GMAP_VAR); this.map.setOninit(GoogleMapController.LOAD_POINTS_INITIALIZE); this.map.setZoom(GoogleMapController.MAP_ZOOM_INITIAL); this.map.setStyle(GoogleMapController.MAP_STYLE); this.map.setGmapKey(this.getGmapKey()); this.map.setLat(this.pointX); this.map.setLng(this.pointY); this.map.setMapType(GoogleMapController.MAP_TYPE_INITIAL); } else { this.map = map; } } /** * getter method * * @return point */ public MapData getPoint() { return this.point; } /** * setter methods * * @param point * point */ public void setPoint(final MapData point) { this.point = point; } public Boolean getRefresh() { return refresh; } public void setRefresh(Boolean refresh) { this.refresh = refresh; } }
jsp controller
/** * PlaceDetailControlller.java 1.00 Jun 08, 2007 * * Copyright (c) PROCON DATA Datenverarbeitung Gesellschaft m.b.H. * * Project : GatheringPlace * Author : MPF * Email : markus_pfeiffer@aon.at * * last change by : MPF, Jun 14, 2007 */ package at.pcd.wam.technologie.controller; import java.util.LinkedList; import java.util.List; import javax.faces.event.ActionEvent; import javax.faces.event.ValueChangeEvent; import javax.faces.model.DataModel; import javax.faces.model.ListDataModel; import javax.faces.model.SelectItem; import org.apache.myfaces.component.html.ext.HtmlDataTable; import org.apache.myfaces.component.html.ext.HtmlSelectOneMenu; import at.pcd.wam.technologie.controller.helper.ComponentSupport; import at.pcd.wam.technologie.controller.model.FormularRequestModel; import at.pcd.wam.technologie.controller.model.PlaceDetailModel; public class PlaceDetailController { //------------------------------------------------------------------------------------------------------------------ // FIELDS //------------------------------------------------------------------------------------------------------------------ /** place detail model */ private PlaceDetailModel placeDetailModel; /** binding view data table for case data */ private HtmlDataTable caseDataDataTable; /** contains drop down possibles */ private List<SelectItem> dropDownPossibles; /** current selected from the drop down */ private String dropDownSelected; /** contains user formular request input */ private FormularRequestModel formModel; /** default value for drop down */ private static final String DEFAULT_VALUE = ""; private HtmlSelectOneMenu dropDown = new HtmlSelectOneMenu(); //------------------------------------------------------------------------------------------------------------------ // CONSTRUCTOR //------------------------------------------------------------------------------------------------------------------ /** * constructor */ public PlaceDetailController() { this.placeDetailModel = new PlaceDetailModel(); this.dropDownPossibles = new LinkedList<SelectItem>(); this.formModel = new FormularRequestModel(); /* load drop down possible values and set them */ this.loadDropDownPossibles(); /* get the given parameters [0]..contains dbk [1]..contains check */ LinkedList<String> param = this.getParameter(); if (this.checkValidation()) { /* load data from db and store at model */ this.placeDetailModel.lookupData(param.get(0)); /* overwork the map to set the correct values */ this.overworkMap(this.placeDetailModel.getMasterData().getGeoX(), this.placeDetailModel.getMasterData().getGeoY()); } } //------------------------------------------------------------------------------------------------------------------ // HELPER METHODS //------------------------------------------------------------------------------------------------------------------ /** * check if value change event is valid * @param ve value change event * @return true .. value change event is valid - permission to execute changes * false .. value change event is invalid - no permission to change something */ private boolean valueChangeValid(final ValueChangeEvent ve) { /* ignore value change event if old value is null and new equals "" */ return (!(ve.getOldValue() == null && ve.getNewValue().equals(""))); } /** * clear formular data */ private void clearFormularData() { this.formModel = new FormularRequestModel(); this.dropDownSelected = PlaceDetailController.DEFAULT_VALUE; } /** * insert request data into data base */ private void insertRequestData() { /* insert data */ this.placeDetailModel.insertRequestData(this.formModel, this.dropDownSelected); /* clear view data */ } /** * ui method * insert user request data * @param event action event */ public void doInsert (final ActionEvent event) { this.insertRequestData(); } /** * ui method * drop down value changed by user * @param event value changed event */ public void dropDownValueChanged(final ValueChangeEvent event) { if (this.valueChangeValid(event)) { /* set new selected value */ this.dropDownSelected = (String) event.getNewValue(); } } /** * load drop down possible data */ private void loadDropDownPossibles() { /* load drop down possible values and set */ LinkedList<String> tmpList = this.placeDetailModel.loadDropDownValues(); /* add default value */ this.dropDownPossibles.add(new SelectItem(PlaceDetailController.DEFAULT_VALUE)); /* set default dropDownSelected */ this.dropDownSelected = PlaceDetailController.DEFAULT_VALUE; for (String element : tmpList) { /* add to view list */ this.dropDownPossibles.add(new SelectItem(element)); } /* clear tmp list */ tmpList = null; } /** * get parameter from the request bean <code>{@link GetController}</code> * @return list which contains parameter values */ private LinkedList<String> getParameter() { /* get the current parameters */ ParameterController paramContrl = (ParameterController) ComponentSupport.getSessionVariable("paramContrl"); LinkedList<String> list = new LinkedList<String>(); /* set this dbk */ list.add(paramContrl.getDbk()); /* set this check */ list.add(paramContrl.getCheck()); /* clear reference */ paramContrl = null; return list; } /** * check the validation of the hash value for the dbk * @return true .. valid * false .. invalid */ private boolean checkValidation() { //FIXME soll überprüfen ob der hash(check) eh zum dbk passt return true; } /** * check the validation of the get parameter and if valid then set map values * @param geoX geocoordinate x * @param geoY geocoordinate y */ private void overworkMap(final String geoX, final String geoY) { /* get map controller to modify */ GoogleMapController gMapCont = (GoogleMapController) ComponentSupport.getSessionVariable("gmBean"); /* center the map to the point */ gMapCont.centerMap2Point(geoX, geoY); /* add point to the map */ gMapCont.addPoint2Map(geoX, geoY, this.placeDetailModel.getMasterData().getAddress()); /* clear reference */ gMapCont = null; } //------------------------------------------------------------------------------------------------------------------ // GETTER/SETTER //------------------------------------------------------------------------------------------------------------------ /** * getter method * @return placeDetailModel */ public PlaceDetailModel getPlaceDetailModel() { return this.placeDetailModel; } /** * setter method * @param placeDetailModel place detail model */ public void setPlaceDetailModel(final PlaceDetailModel placeDetailModel) { this.placeDetailModel = placeDetailModel; } /** * ui method * getter method * @return address */ public String getAddress() { return this.placeDetailModel.getMasterData().getAddress(); } /** * ui method * setter method * @param address address */ public void setAddress(final String address) { this.placeDetailModel.getMasterData().setAddress(address); } /** * ui method * getter method * @return boroughNumber */ public String getBoroughNumber() { return this.placeDetailModel.getMasterData().getBoroughNumber(); } /** * ui method * getter method * @param boroughNumber boroughNumber */ public void setBoroughNumber(final String boroughNumber) { this.placeDetailModel.getMasterData().setBoroughNumber(boroughNumber); } /** * ui method * getter method * @return collectorLocaltity */ public String getCollectorLocaltity() { return this.placeDetailModel.getMasterData().getCollectorLocaltity(); } /** * ui method * setter method * @param collectorLocaltity collectorLocaltity */ public void setCollectorLocaltity(final String collectorLocaltity) { this.placeDetailModel.getMasterData().setCollectorLocaltity(collectorLocaltity); } /** * ui method * getter method * @return dbk */ public String getDbk() { return this.placeDetailModel.getMasterData().getDbk(); } /** * ui method * setter method * @param dbk dbk */ public void setDbk(final String dbk) { this.placeDetailModel.getMasterData().setDbk(dbk); } /** * ui method * getter method * @return district */ public String getDistrict() { return this.placeDetailModel.getMasterData().getDistrict(); } /** * ui method * setter method * @param district district */ public void setDistrict(final String district) { this.placeDetailModel.getMasterData().setDistrict(district); } /** * ui method * getter method * @return locality */ public String getLocality() { return this.placeDetailModel.getMasterData().getLocality(); } /** * ui method * setter method * @param locality locality */ public void setLocality(final String locality) { this.placeDetailModel.getMasterData().setLocality(locality); } /** * ui method * getter method * @return localityNumber */ public Integer getLocalityNumber() { return this.placeDetailModel.getMasterData().getLocalityNumber(); } /** * ui method * setter method * @param localityNumber localityNumber */ public void setLocalityNumber(final Integer localityNumber) { this.placeDetailModel.getMasterData().setLocalityNumber(localityNumber); } /** * ui method * getter method * @return zip */ public String getZip() { return this.placeDetailModel.getMasterData().getZip(); } /** * ui method * setter method * @param zip zip */ public void setZip(final String zip) { this.placeDetailModel.getMasterData().setZip(zip); } /** * getter method * @return caseDataDataTable data table */ public HtmlDataTable getCaseDataDataTable() { return this.caseDataDataTable; } /** * setter method * @param caseDataDataTable data table */ public void setCaseDataDataTable(final HtmlDataTable caseDataDataTable) { this.caseDataDataTable = caseDataDataTable; } /** * ui method * getter method * @return case data */ public DataModel getCaseData() { return new ListDataModel(this.placeDetailModel.getCaseData().getList()); } /** * ui method * getter method * @return dropDownPossibles drop down possibles */ public List<SelectItem> getDropDownPossibles() { return this.dropDownPossibles; } /** * ui method * setter method * @param dropDownPossibles drop down possibles */ public void setDropDownPossibles(final List<SelectItem> dropDownPossibles) { this.dropDownPossibles = dropDownPossibles; } /** * ui method * getter method * @return dropDownSelected drop down selected */ public String getDropDownSelected() { return this.dropDownSelected; } /** * ui method * setter method * @param dropDownSelected drop down selected */ public void setDropDownSelected(final String dropDownSelected) { this.dropDownSelected = dropDownSelected; } /** * ui method * getter method * @return callNumber */ public String getCallNumber() { return this.formModel.getCallNumber(); } /** * ui method * setter method * @param callNumber callNumber */ public void setCallNumber(final String callNumber) { this.formModel.setCallNumber(callNumber); } /** * ui method * getter method * @return email */ public String getEmailFrom() { return this.formModel.getEmailFrom(); } /** * ui method * setter method * @param emailFrom emailFrom */ public void setEmailFrom(final String emailFrom) { this.formModel.setEmailFrom(emailFrom); } /** * ui method * getter method * @return forename */ public String getForename() { return this.formModel.getForename(); } /** * ui method * setter method * @param forename forename */ public void setForename(final String forename) { this.formModel.setForename(forename); } /** * ui method * getter method * @return locality */ public String getLocalityF() { return this.formModel.getLocality(); } /** * ui method * setter method * @param locality locality */ public void setLocalityF(final String locality) { this.formModel.setLocality(locality); } /** * ui method * getter method * @return message */ public String getMessage() { return this.formModel.getMessage(); } /** * ui method * setter method * @param message message */ public void setMessage(final String message) { this.formModel.setMessage(message); } /** * ui method * getter method * @return surname */ public String getSurname() { return this.formModel.getSurname(); } /** * ui method * setter method * @param surname surname */ public void setSurname(final String surname) { this.formModel.setSurname(surname); } /** * ui method * getter method * @return title */ public String getTitle() { return this.formModel.getTitle(); } /** * ui method * setter method * @param title title */ public void setTitle(final String title) { this.formModel.setTitle(title); } /** * ui method * getter method * @return zip */ public String getZipF() { return this.formModel.getZip(); } /** * ui method * setter method * @param zip zip */ public void setZipF(final String zip) { this.formModel.setZip(zip); } public HtmlSelectOneMenu getDropDown() { return dropDown; } public void setDropDown(HtmlSelectOneMenu dropDown) { this.dropDown = dropDown; } }