javaserverfaces-spec-public
  1. javaserverfaces-spec-public
  2. JAVASERVERFACES_SPEC_PUBLIC-145

invokeOnComponent: a new way to find a node in a UIComponent tree.

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Component/s: Uncategorized
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Sun

    • Issuezilla Id:
      145

      Description

      Summary:
      ========

      a new way to find a node in a UIComponent tree.

      Perception Problems solved by this proposal
      ===========================================

      JSF is just starting to win over people as a good AJAX solution, as
      evidenced by discussion on about the Blueprints JSF AJAXs components on
      TheServerSide.com. Having this level of support in the Core API will
      demonstrate that the JSF development team is showing thought leadership
      in the AJAX area.

      Technical Problems solved by this proposal
      ==========================================

      Here are just a few of the problems solved by this proposal.

      1. the "findComponent" problem.

      Several people on the external forums and mailing lists, as well as
      people inside of Sun, including the Braveheart team, have pointed out
      the problems with our existing implementation of
      UIComponent.findComponent(). This method does fulfill the contract in
      its javadoc, but that contract doesn't always fulfill the user's
      expectations of a findComponent() type method.

      2. The "find component while preserving context" problem

      Currently there is no way to find a specific component nested within
      an iterating component, such as UIData, while preserving the state of
      that component relative to its parent. For example. If we have a
      UIData that points at a database table with 10,000 rows, and, for some
      reason, we want the third colum of the 1972nd row, we have no way to
      get that component with the proper data.

      3. Run the JSF lifecycle just on a part of the component tree.

      One approach for doing AJAX with JSF is to render the tree once using
      the full HTTP/Request Response and JSF lifecycle, and then render
      changes to subtrees over AJAX.

      Technical Details of the Proposal
      =================================

      1. Add new method to UIComponent:

      /**
      *

      • <p>This method is similar to {@link #findComponent}

        but it doesn't

      • take {@link NamingContainer}

        s into account. It just literally

      • searches through the children of this node looking for a match to
      • the argument clientId.</p>
        *
      • <p>The default implementation will first check if
      • this.getClientId() is equal to the argument clientId. If so, call
      • the {@link Callback#invoke}

        method on the argument callback,

      • passing through the FacesContext argument and passing this as the
      • component argument. If an Exception is thrown by the callback,
      • wrap it in a FacesException and re-throw it. Otherwise, return
      • true.</p>
        *
      • <p>Otherwise, for each component returned by {@link * #getFacetsAndChildrenIterator}

        , call invokeOnComponent() passing

      • the arguments to this method, in order. The first time
      • invokeOnComponent() returns true, abort traversing the rest of the
      • iterator and return true.</p>
        *
      • <p>If none of the UIComponent elements of the Iterator returned
      • true from invokeOnComponent(), return false.</p>
        *
      • @since 1.2
        *
      • @param context the {@link FacesContext}

        for the current request
        *

      • @param clientId the client identifier of the component to be passed
      • to the argument callback.
        *
      • @param callback an implementation of the Callback interface.
        *
      • @throws NullPointerException if any of the arguments are null
        *
      • @throws FacesException if the argument Callback throws an
      • Exception, it is wrapped in a FacesException and re-thrown.
        *
      • @returns true if the a component with the given clientId is found,
      • the callback method was sucessfully invoked passing that component
      • as an argument, and no Exception was thrown. Returns false if no
      • component with the given clientId is found.
        *
        */

      boolean invokeOnComponent(FacesContext context, String clientId, Callback
      callback) throws FacesException;

      2. Add an implementation of this method to UIComponentBase.

      boolean invokeOnComponent(FacesContext context, String clientId,
      Callback callback) {
      if (clientId.equals(this.getClientId(faces)) {
      try

      { callback.invoke(context, this); return true; }

      catch (Exception e)

      { throw new FacesException(e); }

      } else {
      Iterator<UIComponent> itr = this.getFacetsAndChildrenIterator();
      boolean found = false;
      while (itr.hasNext() & !found)

      { found = itr.next().invokeOnComponent(context, clientId, callback); }

      }
      return false;
      }

      3. Add new interface javax.faces.component.ComponentCallback:

      /**

      • <p>A simple callback interace that enables taking action on a
      • specific UIComponent (either facet or child) in the view while
      • preserving any contextual state for that component instance in the
      • view.</p>
        *
        */

      public interface ComponentCallback

      { public void invoke(FacesContext faces, UIComponent component); }
      1. jsf-api-145.tar.gz
        32 kB
        Ed Burns
      2. message.txt
        89 kB
        Ed Burns
      3. message.txt
        25 kB
        Ed Burns

        Activity

        Hide
        Ed Burns added a comment -

        Fix checked in.

        Show
        Ed Burns added a comment - Fix checked in.
        Hide
        Ed Burns added a comment -

        Fix checked in.

        Show
        Ed Burns added a comment - Fix checked in.
        Hide
        Ed Burns added a comment -

        Prepare to delete "spec" subcomponent.

        Show
        Ed Burns added a comment - Prepare to delete "spec" subcomponent.
        Hide
        Ed Burns added a comment -

        Move all to 1.2

        Show
        Ed Burns added a comment - Move all to 1.2
        Hide
        Manfred Riem added a comment -

        Closing resolved issue out

        Show
        Manfred Riem added a comment - Closing resolved issue out

          People

          • Assignee:
            Ed Burns
            Reporter:
            Ed Burns
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: