How to get StreamAddResource up and running

Setup the new AddResource implmenentation in your web.xml

  <context-param>
    <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
    <param-value>org.apache.myfaces.component.html.util.StreamingAddResource</param-value>
  </context-param>

and use the new t:document* tags in your jsp

  • t:document as replacement for html
  • t:documentHead as replacement for head
  • t:documentBody as replacement for body

These new document tags are somewhat special, there are two mode how you can use them.

The classical way

<f:view>
<t:document>
<t:documentHead>
<title>the title</title>
</t:docmentHead>
<t:documentBody>
your body
</t:documentBody>
</t:document>
</f:view>

and a somewhat special way if you would like to place e.g. the documentBody in your header/footer includes

<f:view>
<t:document>
<t:documentHead>
<title>the title</title>
</t:docmentHead>
<t:documentBody state="start" />
your body
<t:documentBody state="end" />
</t:document>
</f:view>

this state attribute is available on all document Tags. Notice that these tags are self-closing tags then. For now at least a

<t:documentBody state="end" />

and

<t:documentHeader state="end" />

IS REQUIRED and you CAN NOT use these document tags without the new StreamingAddResource. I'll fix this limitation as soon as possible.

Also there are a couple of attributes needed at documentBody to be a full replacement for the html body tag but this will be done by someone else soon (wink)

I hope there are not too many bugs.

Have fun!

Caveats

There are changes in behaviour between StreamingAddResources and and the DefaultAddResource. Those are documented here

CSS loading on head

CSS loaded at head location are loaded using an intermediate stylesheet, that "import" the files your requested. So instead of

<head>
    <link rel="stylesheet" href="org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader/12003983/component/css1.css" type="text/css"/>
    <link rel="stylesheet" href="org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader/12003983/component/css2.css" type="text/css"/>
....

You will get

<head>
    <link rel="stylesheet" href="/webapp/faces/myFacesExtensionResource/org.apache.myfaces.component.html.util.StreamingResourceLoader/12003983/1566/header.css" type="text/css" />

and the header.css will contian @import() rules

Javascript on head

If some of your componnents that absolutely requires Javascript on head (so that script get executed, for whatever reason, before <body> is reached), this component probable uses addResources.addJavaScriptAtLocation(.... AddResources.LOCATION_HEAD ....). StreamingAddResource will silently fallback to loading the javascript at current position instead of head.

  • No labels