0

I have a database where I keep uploading GPS information that I want to show in a JSF page. In order to do that periodically, I am using the poll element from PrimeFaces, however, the queries keeps returning the same values, even though they are being updated on the database. I've already tried that with @SessionScope and @RequestScope but it seems that this is not where the problem is. Any help would be very appreciated! Bellow are the codes I am using for the tasks:

View:

<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>

Backing 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

Update: I solved it. My fault since the begining, I forgot to close the Entity Manager Factory and the Entity Manger objects, which caused to keep retrieving the same query always. Closing both objects mentioned resolved my problem, that had nothing to do with Primefaces or JSF - I am sorry for that. Funny fact is that when I did the Stand Alone Test Unit I forgot to close the refered objects as well and even though it was capable to retrieve the updated data. Thank you everyone who tryed to help me :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
E. Fernandes
  • 3,889
  • 4
  • 30
  • 48
  • In other words, the `usr.getCoordinate()` returns the same values everytime? Okay, but why exactly do you think that this problem is related to JSF? Does the problem disappear when you invoke that using a different front end such as a plain servlet, or a different MVC framework, or even as a standalone unit test program? – BalusC Nov 17 '13 at 14:09
  • Yes, everytime I run usr.getCoordinate() it returns the same value. I tested it as a standalone test unit and it does update the values from the database, the problem happens when I run it from the backbean. – E. Fernandes Nov 17 '13 at 15:19
  • Have you tried to update `@all` ? – Lukas Eichler Nov 17 '13 at 19:45

0 Answers0