示例#1
0
  /**
   * Installs a <code>SystemEventListener</code> on the <code>UIViewRoot</code> to track components
   * added to or removed from the view.
   */
  public void startTrackViewModifications(FacesContext ctx, UIViewRoot root) {

    if (modListener == null) {
      modListener = new AddRemoveListener(ctx);
      root.subscribeToViewEvent(PostAddToViewEvent.class, modListener);
      root.subscribeToViewEvent(PreRemoveFromViewEvent.class, modListener);
    }
    setTrackViewModifications(true);
  }
  /** Constructor. */
  public DynamicParentComponent() {
    setRendererType("com.sun.faces.test.agnostic.statesaving.basic.DynamicParentComponentRenderer");

    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot root = context.getViewRoot();

    if (!context.isPostback()) {
      root.subscribeToViewEvent(PreRenderViewEvent.class, this);
    }
  }
示例#3
0
  /**
   * Register callback to be executed only on whole scope destroying (not single object).
   *
   * @see Scope for more details
   */
  @Override
  public void registerDestructionCallback(String name, Runnable callback) {
    // logger.trace("registerDestructionCallback for bean " + name);

    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    ViewScopeViewMapListener listener =
        new ViewScopeViewMapListener(viewRoot, name, callback, this);

    viewRoot.subscribeToViewEvent(PreDestroyViewMapEvent.class, listener);

    HttpSession httpSession =
        (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);

    final Set<ViewScopeViewMapListener> sessionListeners;

    if (sessionToListeners.containsKey(httpSession)) {
      sessionListeners = sessionToListeners.get(httpSession);
    } else {
      synchronized (sessionToListeners) {
        if (sessionToListeners.containsKey(httpSession)) {
          sessionListeners = sessionToListeners.get(httpSession);
        } else {
          sessionListeners = new HashSet<>();
          sessionToListeners.put(httpSession, sessionListeners);
        }
      }
    }

    synchronized (sessionListeners) {
      sessionListeners.add(listener);
    }

    if (!FacesContext.getCurrentInstance()
        .getExternalContext()
        .getSessionMap()
        .containsKey("sessionBindingListener")) {
      FacesContext.getCurrentInstance()
          .getExternalContext()
          .getSessionMap()
          .put("sessionBindingListener", this);
    }
  }
示例#4
0
 //
 // Constructor: Subscribes to PreRenderView Event(s)
 //
 public TableComponent() {
   setRendererType("component");
   FacesContext context = FacesContext.getCurrentInstance();
   UIViewRoot root = context.getViewRoot();
   root.subscribeToViewEvent(PreRenderViewEvent.class, this);
 }