You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rogers Reilly <ro...@s-rod.com> on 2006/02/05 04:25:50 UTC
[shale] reusable parameterized snippets in Tiles/Clay/Facelets
Hi,
We're refactoring the view layers of a couple medium-sized projects from
hodgepodge JSP to JSF/Shale, and are trying to choose a templating
option to stick on top. My first thought was to just do Tiles, but I
quickly ran into trouble when trying to parameterize a small Tile with
JSF components inside. I'm able to "put" a bean into my Tile, but
<tiles:importAttribute /> is only making the bean available to Tiles
tags, not to JSF #{bean.xxx} accessors inside (and even if I were to get
the sucker in somehow, I'd be nervous about it referencing the same JSF
stuff once it got passed through Tiles).
So I hit the web and found Clay and Facelets (which being native JSF
technologies I assume would knock out that last concern). I'm not
asking anyone to tell me one's better than the other; rather, I've got a
specific use case I'd like to understand in Clay. Unfortunately I
haven't found any documentation about it online, apart from David Geary
describing Clay as "a way to parameterize a JSP page for different
managed beans" in his weblog. (after demo'ing the Tapestry-esque HTML
stuff, he then says, "I haven't even shown you how to implement
parameterized subtrees." :-( )
What I need is to define a short JSP (call it snippet.jsp) along these
lines:
<h:outputText value="#{storyBean.title}" />
<h:outputText value="#{authorBean.byline}" />
<h:outputText value="#{storyBean.body}" />
and then reuse it in many different pages a la:
<clay:clay jsfid="snippet_jsp" storyBean="#{backingBean.story}"
authorBean="#{backingBean.author}" />
Ideally I'd be able to do this inside a c:forEach loop as well ... which
I've heard is hairy in JSF. Anyway, as I said, I haven't been able to
track down any examples of somebody doing this. The Apache docs
<http://struts.apache.org/struts-shale/features-reusable-views.html>
make it sound like the most you can do is define a Clay component that
extends an existing JSF tag and then resuse /that /all over the place,
which is fine, but I really need to define a whole chunk of
parameterized code. I don't see any kind of "path" attribute, so maybe
to implement this, I would have to implement my own custom component and
then wrap it in a Clay jsfid--at which point, I might as well just use
the custom tag over and over. (I should mention that snippet.jsp won't
actually be that simple, so a canned datalist component isn't going to
cut it.)
I know this type of thing can be done in Facelets (see code below), but
my preference is to stay within Shale if possible. Can anybody point me
to any example of parameterized snippets along these lines? David's
general description of Clay in his weblog made it sound like exactly
what I was looking for, but I haven't been able to nail down the params
functionality.
Thanks in advance.
-Rogers
here's an example of snippet/parameter usage in Facelets, if it
enlightens my rambling above at all ...
|<!-- include.xhtml -->
...
<span id="leftNav">
<ui:include src="/WEB-INF/siteNav.xhtml">
<ui:param name="menuBean" value="#{backingBean.options}"/>
</ui:include>
</span>
...|
|<!-- siteNav.xhtml -->
...
<ui:composition>
<!-- myfaces tomahawk components -->
<t:tree2 value="#{menuBean}" var="opt">
...
</t:tree2>
</ui:composition>
...|
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org