You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Blake Sullivan <bl...@oracle.com> on 2009/04/30 20:42:30 UTC

Re: [TRINIDAD][API] JIRA-1465 Allow public access to the UIXComponent renderer, if any

Simon,

Thanks for the quick reply.  You are right,  it is much better not to be 
messing with the RenderKit approach is theoretically unsafe because we 
are assuming that any component with a Renderer actually got the 
Renderer through the RenderKitFactory, but I don't know of any 
components like that and I suspect that the component could have other 
problems.  So I will switch to using the factory.

PanelFormLayoutRenderer uses the approach that use propose and Adam 
included the following comment:

      // =-= AEW Might consider altering the following approach of 
getting the
      //         child renderer in case anyone wants to use renderer 
decoration.

I'm not sure what issue Adam is referring to here, since I would have 
thought that anyone doing Renderer decoration would have done so by 
decorating the RenderKitFactory.

-- Blake Sullivan

Simon Lessard said the following On 4/30/2009 10:55 AM PT:
> Hi,
>
> I won't -1 it, most likely +0, but I'm curious, why can't 
> RenderKit.getRenderer be used for that case use case? The only case it 
> does not cover would be a component not getting its Renderer the 
> standard way, but to my knowledge all UIXComponent do so I'm not sure.
>
>
> Regards,
>
> ~ Simon
>
> On Thu, Apr 30, 2009 at 1:47 PM, Blake Sullivan 
> <blake.sullivan@oracle.com <ma...@oracle.com>> wrote:
>
>     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
>
>