我有一个托管 bean,它从数据库中获取点并将它们添加到覆盖中。在同一个托管 bean 中,我从数据库中检索相关数据,并在用户单击任何标记时显示它们。
直到这里没有问题。我的托管 bean 使用@SessionScoped
. 但是,当我尝试将项目添加到系统时,它会添加,但它仍然显示以前版本的数据。当我将其更改@ViewScoped
为根据请求检索数据时,基本上它将数据作为其最后更新的状态。
这是我的豆:
@ManagedBean
@SessionScoped
public class MapBean implements Serializable{
private static final long serialVersionUID = 1L;
private MapModel simpleModel;
private Marker marker;
//genel
private String projectName, projectExp, projectCoordLong, projectCoordLat, district, sector, workStatus, assistant, bidName, company, bidCost, costPaid;
//getters and setters ...
//süre bilgileri
private String processTime = "0", startDate, endDate;
//teknik bilgiler
private String parcel, planStatus, roadLength, roadWidth, totalArea, extraInfo;
//genel devam
private String unitOffer, approxCost, projectCost, fileNu;
//idare kontrol teşk.
private String chef, arch, strEng, landArch, elecEng, geoEng, machEng, mapEng, planEng;
//ihale önce takip
private String assistantBefore, engArch;
//uygulamacı birim kontrol teşkilatı
private String mudYard, mim, ins, peyz, elek;
//fima iletişim bilgileri
private String compResp, compResJob, compTel, compAddress, compMail,total;
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public MapModel getSimpleModel() {
return simpleModel;
}
//con to db
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/projetakip?useUnicode=true&characterEncoding=utf-8", "root", "");
Statement stmt = con.createStatement();
String SQL;
ResultSet rs;
public MapBean() throws Exception {
SQL = "select * from projects";
rs = stmt.executeQuery(SQL);
simpleModel = new DefaultMapModel();
LatLng coord1;
//add markers to map
while (rs.next()) {
coord1 = new LatLng(Double.valueOf(rs.getString("projectCoordLat")), Double.valueOf(rs.getString("projectCoordLon")));
simpleModel.addOverlay(new Marker(coord1, rs.getString("id"), "", "http://maps.google.com/mapfiles/ms/micons/red-dot.png"));
}
}
public void onMarkerSelect(OverlaySelectEvent event) throws Exception {
marker = (Marker) event.getOverlay();
Statement stmt2= con.createStatement();
String markerSQL = "select * from projects where id=" + marker.getTitle();
ResultSet markerRs = stmt.executeQuery(markerSQL);
while (markerRs.next()) {
//proje bilgisi
projectName = markerRs.getString("projectName");
startDate = markerRs.getString("startDate");
endDate = markerRs.getString("endDate");
company = markerRs.getString("company");
bidCost = markerRs.getString("biddCost");
sector = markerRs.getString("sector");
workStatus = markerRs.getString("workStatus");
projectExp = markerRs.getString("projectExp");
projectCoordLat = markerRs.getString("projectCoordLat");
projectCoordLong = markerRs.getString("projectCoordLon");
district = markerRs.getString("district");
assistant = markerRs.getString("assistant");
bidName = markerRs.getString("bidName");
costPaid = markerRs.getString("costPaid");
processTime = markerRs.getString("processTime");
//teknik bilgiler
parcel = markerRs.getString("parcel");
planStatus = markerRs.getString("planStatus");
roadWidth = markerRs.getString("roadWidth");
roadLength = markerRs.getString("roadLength");
totalArea = markerRs.getString("totalArea");
extraInfo = markerRs.getString("extraInfo");
unitOffer = markerRs.getString("unitOffer");
approxCost = markerRs.getString("approxCost");
projectCost = markerRs.getString("projectCost");
fileNu = markerRs.getString("fileNu");
//idare kontrol teşkilatı
chef = markerRs.getString("chef");
arch = markerRs.getString("arch");
strEng = markerRs.getString("strEng");
landArch = markerRs.getString("landArch");
elecEng = markerRs.getString("elecEng");
geoEng = markerRs.getString("geoEng");
machEng = markerRs.getString("machEng");
mapEng = markerRs.getString("mapEng");
planEng = markerRs.getString("planEng");
//uyg birim teşk
mudYard = markerRs.getString("mdYard");
mim = markerRs.getString("mim");
ins = markerRs.getString("ins");
peyz = markerRs.getString("peyz");
elek = markerRs.getString("elek");
assistantBefore = markerRs.getString("assistantBefore");
engArch = markerRs.getString("engArch");
//firma iletişim
compResp = markerRs.getString("compRes");
compResJob = markerRs.getString("compResJob");
compTel = markerRs.getString("compTel");
compAddress = markerRs.getString("compAddress");
compMail = markerRs.getString("compMail");
}
//addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Seçilen proje:", marker.getTitle()));
}
public Marker getMarker() {
return marker;
}
}
这是我的 jsf 片段:
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<p:growl id="growl" showDetail="true"/>
<p:gmap center="41.067445,29.047749" zoom="11" type="HYBRID" model="#{mapBean.simpleModel}" style="width:100%;height:100%" streetView="true">
<p:ajax event="overlaySelect" listener="#{mapBean.onMarkerSelect}" update="growl"/>
<p:gmapInfoWindow rendered="true">
<h:form id="form">
<p:tabView id="tabView" dynamic="true" cache="true" orientation="top" effect="blind" style="font-size: 10px;font-weight: bold;">
<p:tab id="tab1" title="Proje Bilgileri" >
<h:panelGrid columns="2" cellpadding="3">
<h:outputText value="Proje Adı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.projectName}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Proje Detayı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.projectExp}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Proje Koordinatları: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.projectCoordLat}, #{mapBean.projectCoordLong}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İlçe: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.district}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Sektör: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.sector}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İş Durumu: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.workStatus}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Sorumlu Müd. Yard.: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.assistant}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İhale Adı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.bidName}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Firma: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.company}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İhale Bedeli: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.bidCost}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Ödenen Hak Ediş Tutarı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.costPaid}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="SÜRE BİLGİSİ" style="font-weight: bold; font-size: 13px; float: right; font-style: italic"/><p:separator />
<h:outputText value="Başlangıç Tarihi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.startDate}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İşin Süresi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.processTime}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Bitiş Tarihi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.endDate}" style="font-weight: bold; font-size: 13px;"/>
</h:panelGrid>
</p:tab>
<p:tab id="tab2" title="Teknik Bilgiler">
<h:panelGrid columns="2" cellpadding="3">
<h:outputText value="Ada/Parsel: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.parcel}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Plan Durumu: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.planStatus}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Yolun Genişliği: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.roadWidth}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Yolun Uzunluğu: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.roadLength}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Toplam Alan: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.totalArea}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İlave Bilgi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.extraInfo}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Teklif Birim Fiyat: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.unitOffer}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Yapım Yaklaşık Maliyeti: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.approxCost}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Proje Maliyeti: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.projectCost}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Dosya Kodu: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.fileNu}" style="font-weight: bold; font-size: 13px;"/>
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="Proje Teşkilatı">
<h:panelGrid columns="2" cellpadding="3">
<h:outputText value="Şef: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.chef}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Mimar: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.arch}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İnşaat Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.strEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Peyzaj Mimarı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.landArch}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Elektrik Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.elecEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Jeoloji Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.geoEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Makine Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.machEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Harita Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.mapEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Şehir Plancısı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.planEng}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İHALE ÖNCESİ TAKİP" style="font-weight: bold; font-size: 13px; float: right; font-style: italic"/><p:separator />
<h:outputText value="Sorumlu Müd. Yard.: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.assistantBefore}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Sorumlu Müh./Mimar: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.engArch}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="UYGULAMACI KONTROL TEŞKİLATI" style="font-weight: bold; font-size: 13px; float: right; font-style: italic"/><p:separator />
<h:outputText value="Müdür Yard.: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.mudYard}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Mimar: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.mim}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="İnşaat Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.ins}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Peyzaj Mimarı: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.peyz}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Elektrik Mühendisi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.elek}" style="font-weight: bold; font-size: 13px;"/>
</h:panelGrid>
</p:tab>
<p:tab id="tab4" title="Firma Bilgisi">
<h:panelGrid columns="2" cellpadding="3">
<h:outputText value="Yetkili Kişi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.compResp}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Görevi: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.compResJob}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Telefon: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.compTel}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="Adres: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.compAddress}" style="font-weight: bold; font-size: 13px;"/>
<h:outputText value="E-Posta: " style="font-size: 13px;"/>
<h:outputText value="#{mapBean.compMail}" style="font-weight: bold; font-size: 13px;"/>
</h:panelGrid>
</p:tab>
<p:tab title="Yorumlar">
<h:panelGrid columns="2" cellpadding="10">
<p:graphicImage value="/images/pdf.png" />
<h:outputText value=""/>
</h:panelGrid>
</p:tab>
<p:tab title="Dosyalar">
<h:panelGrid columns="2" cellpadding="10">
<p:graphicImage value="/images/pdf.png" />
<h:outputText value=""/>
</h:panelGrid>
</p:tab>
<p:tab title="Resimler">
<h:panelGrid columns="2" cellpadding="10">
<p:graphicImage value="/images/pdf.png" />
<h:outputText value=""/>
</h:panelGrid>
</p:tab>
</p:tabView>
<br />
<center>
<h:outputText value="Toplam Proje Sayısı: #{mapBean.total}" style="font-size: 13px;"/>
</center>
</h:form>
</p:gmapInfoWindow>
</p:gmap>
如图所示,我单击一个标记,它会在选项卡中显示数据。当我使用@SessionBean
它时,它会填充所有选项卡,但不会在当前会话中从数据库中获取最后更新。
当我使用@ViewScoped
它时,它会识别最后的更新,但只填充第一个选项卡。其他都是空的。
我怎样才能做到这一点?任何帮助将不胜感激。