title: Why is my Primefaces.current() returning null
body: <p>So, I have this page:</p>
  <pre><code>@Named(&quot;ManagementPage&quot;)
  @ViewScoped
  @Getter
  @Setter
  @Join(path = &quot;/{appScope}/admin/management&quot;,
          to = &quot;/pages/scoped/managementOverview.xhtml&quot;)
  @Page(
          group = &quot;kitchen&quot;,
          icon = &quot;mdi mdi-comment-text&quot;,
          key = &quot;management&quot;,
          navigation = Page.Navigation.ADMIN_SCOPED,
          outcome = &quot;/pages/scoped/managementOverview.xhtml&quot;,
          auth = @PageAuth(value = &quot;MANAGER_ACCESS&quot;, scoped = true))
  public class ManagementPage implements Serializable {
  private static final long serialVersionUID = 1L;
  
      @Inject
      private ManagementModel model;
  
      @PostConstruct
      public void init() {
          this.model.init();
      }
  }
  </code></pre>
  <p>It's ViewScoped. And the model for it is:</p>
  <pre><code>
  @Log4j
  @Dependent
  @Getter
  @Setter
  public class ManagementModel implements Serializable {
  ...
  }
  </code></pre>
  <p>I want, whenever I receive an event, to refresh some UI on the frontend (I'm using JSF). For that, I've created this dispatcher:</p>
  <pre><code>
  @ApplicationScoped
  public class OrderEventDispatcher {
  
      private static final List&lt;ManagementModel&gt; subscriptions = new ArrayList&lt;&gt;();
  
      public static void addSubscriber(ManagementModel subscriber) {
          subscriptions.add(subscriber);
      }
  
      public static void removeSubscriber(ManagementModel subscriber) {
          subscriptions.remove(subscriber);
      }
  
      public void observerOrderCreated(@Observes FrontendEvent frontendEvent) {
          if(frontendEvent instanceof ContentItemCreatedEvent){
              if(!&quot;order&quot;.equals(((ContentItemCreatedEvent) frontendEvent).getTypeKey())){
                  return;
              }
          }
          if(frontendEvent instanceof ContentItemChangedEvent){
              if(!&quot;order&quot;.equals(((ContentItemChangedEvent) frontendEvent).getTypeKey())){
                  return;
              }
          }
          subscriptions.forEach(ManagementModel::orderInit);
      }
  }
  </code></pre>
  <p>(I have implemented a proper <code>equals</code> for this in my model)
  For my dispatcher to work, I'm subcribing with my model to it (the methods are inside the model)</p>
  <pre><code>@PostConstruct
      public void init() {
          id = totalIds++;
          OrderEventDispatcher.addSubscriber(this);
      ...
  </code></pre>
  <p>And then i unsubscribe before I destroy the model:</p>
  <pre><code>@PreDestroy
      public void preDestroy() {
          OrderEventDispatcher.removeSubscriber(this);
      }
  </code></pre>
  <p>And finally, the methods I call from my dispatcher:</p>
  <pre><code>public void orderInit() {
          loadMergedOrders();
          initializeDonut();
          PrimeFaces.current().executeScript(&quot;orderInit()&quot;);
  }
  </code></pre>
  <p>I'm doing all this in order to refresh my page (even when multiple instance of the same page are open) in reaction to an event (some item is created/deleted/modified, of that the FrontendEvent takes care). Now the issue is that my PrimeFaces.current() is always returning null, I've added a breakpoint in the <code>init()</code> method and I tried using PrimeFaces.current() and it worked then, but then when I went through the Dispatcher and into the <code>orderInit()</code> with the debugger I've seen that PrimeFaces.current() now returns <code>null</code>. Does anyone have any idea what I'm doing wrong? If not how to fix this then maybe a different approach to solving this. Thanks for your time!</p>