Hi,

in order to avoid dependency to h:head/body/form BUT be able to
support the "Relocatable Resources" feature, we should change our
renderers for "head", "body" and "form" to check
for any component resource(s) that has been targeted to one of these guys.

This would mean that something like this just works:
<tr:document
  xmlns="http://www.w3.org/1999/xhtml";
  xmlns:f="http://java.sun.com/jsf/core";
  xmlns:h="http://java.sun.com/jsf/html";
  xmlns:tr="http://myfaces.apache.org/trinidad";
  title="TESTER of Scripts">

    <h:outputScript target="body" name="myCoolBody.js"/>
    <h:outputScript target="head" name="anAwesomeHead.js"/>

</tr:document>
==> no need to add the nasty h:head/body.

The call inside of the renderer should be fairly simple:
...
    for(UIComponent comp :
context.getViewRoot().getComponentResources(context, "head"))
    {
      comp.encodeAll(context);
    }
...
Note: We need to render out these resources pretty much BEFORE we end
the particular HTML element (e.g.  "head", "body" or "form")...

In order to avoid duplicated code, I think we want to add a utility
which should be called from particular renderers, like on
CoreRenderer.java (part of the Trinidad API). This would allow
extensions to easily use this new API as well...

suggested change to CoreRenderer.java =>
  /**
   * Hook for rendering the component resources for the <code>target</code>.
   * @param context Current <code>FacesContext</code> object for this request.
   * @param target The target for the resources (e.g. head/body/form)
   *
   * @throws IOException
   */
  protected final void encodeComponentResources(
    FacesContext context,
    String       target) throws IOException
  {
    if(target != null)
    {
      UIViewRoot viewRoot = context.getViewRoot();
      for(UIComponent componentResource :
viewRoot.getComponentResources(context, target))
      {
        componentResource.encodeAll(context);
      }
    }
  }

As a matter of fact the HeadRenderer's encodeEnd() method would simply
look like:

  protected void encodeEnd(
    FacesContext        context,
    RenderingContext arc,
    UIComponent         comp,
    FacesBean           bean) throws IOException
  {
    ResponseWriter rw = context.getResponseWriter();

    // trigger the rendering of targeted resource
    // for the HEAD, on UIViewRoot - if there are
    // any...
    encodeComponentResources(context, "head");

    rw.endElement("head");
  }

-Matthias

-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Reply via email to