我有一个数据库,我继续上传我想在JSF页面中显示的GPS信息。为了定期执行此操作,我使用PrimeFaces中的poll元素,但是,即使在数据库上更新它们,查询仍会返回相同的值。我已经尝试过使用@SessionScope和@RequestScope,但似乎这不是问题所在。任何帮助将非常感谢!贝娄是我用于任务的代码:
查看:
<h:form>
<div id="border">
<div id="googleMap">
<p:gmap id="teste" center="#{clientBean.center}" zoom="17" type="HYBRID"
style="width:950px;height:600px"
model="#{clientBean.polylineModel}"
>
</p:gmap>
<p:poll interval="10" listener="#{clientBean.traceRoute()}" update="teste"/>
</div>
</div>
</h:form>
支持bean:
public void traceRoute() {
//....................................................................//
id = "123456";
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TrackMePU");
EntityManager em = emf.createEntityManager();
UserDAO usrDAO = new UserDAO(em);
//....................................................................//
Polyline polyline = new Polyline();
polylineModel = new DefaultMapModel();
//....................................................................//
UserModel usr;
try {
usr = usrDAO.fetchUser(id);
System.out.println("retrieved usr.getCoordinate() = " + usr.getCoordinate());
String rawdata[] = usr.getCoordinate().split("\\]");
//................................................................//
for (String geolocation : rawdata) {
String parts[] = geolocation.split("\\,");
//............................................................//
double lat = Double.parseDouble(parts[0]);
double lng = Double.parseDouble(parts[1]);
LatLng coo = new LatLng (lat, lng);
System.out.println("coo = " + coo);
//............................................................//
polyline.getPaths().add(coo);
center = coo.getLat()+","+coo.getLng();
//polylineModel.addOverlay(new Marker(coo));
//............................................................//
}//end for
polyline.setStrokeWeight(7);
polyline.setStrokeColor("#FF9900");
polyline.setStrokeOpacity(0.7);
//................................................................//
polylineModel.addOverlay(polyline);
//center = usr.getCoordinate();
//................................................................//
} catch (NoResultException e) {
System.out.println("could not find user = "+id);
}//end catch
//....................................................................//
}//end traceRoute method
更新:我解决了。自从开始以来我的错,我忘了关闭实体管理器工厂和实体管理器对象,这导致始终保持检索相同的查询。关闭提到的两个对象解决了我的问题,这与Primefaces或JSF无关 - 我很抱歉。有趣的事实是,当我做独立测试单元时,我忘记关闭所引用的对象,即使它能够检索更新的数据。感谢所有试图帮助我的人:)。