dev@jsftemplating.java.net

URL support enabled for locating page-fragments

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Sun, 12 Apr 2009 16:29:45 -0700

URL support is now possible when locating page fragments (#include, ui:include, ui:composition, etc.).  Support is not available directly from the browser (for obvious reasons), but server-side support should work for any valid URL supported by Java.  Be careful when using the feature to make sure you're only including trusted content!

Here's a very simple example of how to use this:
test.jsf:

<f:verbatim>
<html>
<head>
<base href="https://jsftemplating.dev.java.net" />
</head>
#include "https://jsftemplating.dev.java.net"
</f:verbatim>

Then request "http://localhost:8080/yourapp/test.jsf" and JSFTemplating's homepage should be displayed instead (although if you examine the html source, you'll see it has 2 <head> sections as expected....).

I'd also like to mention that this change includes some caching for URL-based includes which stores the contents of the URL in request scope.  This is important since the LDM detection will often cause multiple accesses to the URL on a single request (NOTE: in production mode, this will only occur on the first request).  This change speeds up subsequent requests significantly (actual numbers depend on speed of getting content from the URL which may be significant for remote hosts over slow networks, or not too significant for local files).  My testing showed the above test-case took 505,424,223 ns on my machine to check the 1st LDM's accepts() method.  A subsequent call with caching took 1,508,292 ns.  Before caching, subsequent calls took around 176,219,114 ns (not sure why these calls didn't perform even worse -- Java is probably either keeping the URLConnection open between invocations, or perhaps caching and respecting 304 responses.  Anyway... the performance improvement is > 10,000%.  And even better when JSFT is run in production-mode as all of this time is eliminated completely after the 1st request.

Note: dynamic content is NOT supported via this mechanism.  JSFTemplating requires that LayoutDefinition trees be static.  If you want dynamic content, you should create components which are dynamic, use factories which provide dynamic behavior, use events/handlers to manipulate the UIComponent tree, or use binding's which provide dynamic UIComponents (lots of options).

Thanks!

Ken