The proposal is to allow public access to the UIXComponent's Renderer, if any.

UIComponent only allows protected access to the Renderer, which is normally considered an implementation detail of the component. However, because of the Component/Renderer split, information is often only available on the Renderer and only applicable when that Renderer is present.

/**
* Returns the Renderer of this component cast to the specified Renderer type or * <code>null</code> if the component's Renderer isn't of the specified type.
 * @param context FacesContext
 * @param type The Renderer class to return the Renderer as
* @return the Renderer of this component cast to the specified Renderer type
 */
public final <S extends Renderer> S getRendererAs(FacesContext context, Class<S> type)
{
  Renderer renderer = getRenderer(context);

  if (type.isInstance(renderer))
  {
    return type.cast(renderer);
  }
  else
  {
    return null;
  }
}

A concrete example of how this api is used is code to handle embedding style definitions in an HTML document so that the HTML document can be e-mailed and viewed in e-mail readers that don't support external style sheets. This is implemented by having the DocumentRenderer walk the component tree, asking each component for its Renderer and then asking the Renderer what selector it renders when rendering content.

Alternatives would be:
1) Exposing a Selector getComponentSelector() on UIXComponent and a similar method on CoreRenderer

2) Creating subclasses of every single UIXComponent class and exposing an interface with the method to do the same thing. However this would mean that we wouldn't be able to handle the case where a UIXComponent class was used with one of our Renderers directly and would also needlessly deepen the component hierarchy

-- Blake Sullivan

Reply via email to