Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

0

I am trying to update my dataTable every certain time from the Controller with the following code.

if (tiempMilisegundos > 0) {
            timer = new Timer(tiempMilisegundos, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    obtenerCatalogos();
                    org.primefaces.context.RequestContext.getCurrentInstance().update(
                            "tablaAlertasCped");
                }
            });

            timer.start();
        }

But when you get to the RequestContex it shows the following error:

  

Exception in thread "AWT-EventQueue-0"   java.lang.NullPointerException at   org.primefaces.context.RequestContext.getCurrentInstance (RequestContext.java:39)     at   mx.gob.sat.matce.rni.web.controller.AlertasController.getCatalogs (AlertasController.java:235)     at   mx.gob.sat.matce.rni.web.controller.AlertasController $ 1.actionPerformed (AlertasController.java:198)     at javax.swing.Timer.fireActionPerformed (Timer.java:291) at   javax.swing.Timer $ DoPostEvent.run (Timer.java:221) at   java.awt.event.InvocationEvent.dispatch (InvocationEvent.java:209) at   java.awt.EventQueue.dispatchEventImpl (EventQueue.java:642) at   java.awt.EventQueue.access $ 000 (EventQueue.java:85) at   java.awt.EventQueue $ 1.run (EventQueue.java:603) at   java.awt.EventQueue $ 1.run (EventQueue.java:601) at   java.security.AccessController.doPrivileged (Native Method) at   java.security.AccessControlContext $ 1.doIntersectionPrivilege (AccessControlContext.java:87)     at java.awt.EventQueue.dispatchEvent (EventQueue.java:612) at   java.awt.EventDispatchThread.pumpOneEventForFilters (EventDispatchThread.java:269)     at   java.awt.EventDispatchThread.pumpEventsForFilter (EventDispatchThread.java:184)     at   java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:174)     at   java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:169)     at   java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:161)     at java.awt.EventDispatchThread.run (EventDispatchThread.java:122)

Someone will know the reason, I tried the request out of the timer and if it works but in the no longer.

    
asked by jose 08.11.2017 в 20:25
source

1 answer

0

RequestContext.getCurrentInstance() is returning null , and even if it does not help in your problem, this is normal behavior.

The RequestContext of PrimeFaces requires that you can access the JSF FacesContext . But the latter is only accessible from a thread that is processing a request (order) JSF.

When you use a Timer , this executes your code in a different thread that does not know anything about JSF, nor about FacesContext , that's why it returns null .

References in English:

answered by 08.11.2017 в 21:35