On Mon, Apr 13, 2009 at 3:16 PM, David Geary
<clarity.training@gmail.com> wrote:
2009/4/8 Dan Allen <dan.j.allen@gmail.com>
I just thought of a feature I have often needed in Facelets that perhaps we can weave into the VDL. It would be nice to know if a named template has been defined inside the master template. Consider the following example:
page.xhtml
<ui:composition template="/WEB-INF/template.xhtml" ...>
<ui:param name="title" value="VDL Template Page"/>
<ui:define name="content">
<h:outputText value="Hello World" />
</ui:define>
</ui:composition>
template.xhtml
<html ...>
<h:head>
<title>#{not empty title ? title : 'My Site'}</title>
Alternatively, you can do <ui:insert name="title">My Site</ui:insert> if you ui:define title in page.xhtml, although last time I checked, I don't believe that default values were working for ui:insert in Mojarra.
Naturally. But the fallback fragment only partially solves the problem. It doesn't help if you need to perform logic based on whether or not a template is defined, or enforce that two or more templates are defined. The point is, there are many cases when I have encountered a need to know whether it's been defined or not, irregardless of whether a fallback kicks in.
However, that solution (if it works) isn't good enough because page authors should be able to conditionally render any chunk of XHTML, instead of just conditionally inserting with ui:insert. For example, the container div in the example above might have padding and a border, so if it has no content, you'll get a rectangle with a border, instead of nothing. Therefore, you want the page author to be able to conditionally render the div based on whether content has been defined.
Exactly. It's not always so simple.
-Dan