Sean Schofield wrote:
I'm not talking about open/closed state but about application-specific states like a node which is locked renders as a red folder, a node which is not locked renders as a green folder. This can get quite complex when you try to do it using your facet logic. I also don't think we need an alternate renderer. Take the example I mentioned in another post:This will work for most scenarios I suppose. But consider a scenario
where the icons depend on the type of a node object but also on other
attributes like the state of respective node object. That's the scenario
for using IconProvider as you are able to implement any kind of decision
logic there. But I think if makes sense to support both ways. You can
see the IconProvider just as a utility class, a kind of a backing bean
to obtain your image urls.
This is where the "-open" and "-closed" suffixes come into play. These are the only two states that I could imagine would ever apply. I admit that if there are more, this solution starts to break down.
Anyways, the component will tell the renderer to render the node and include information about the node state (that info would remain independent of the actual node object - same as you have it now.) The renderer would look for a facet based on the type name (and the appropriate suffix.)
This would seem to cover your scenario but maybe I am missing
something. If we still need the IconProvider then this could be
something handled by an alternate renderer perhaps?
<x:tree value="#{treeData}" var="node">
<x:treeIconProvider class="my.very.special.NodeIconProvider"/>
<f:facet name="branch-open">
<x:treeNodeIcon/>
<h:outputText value="#{node.description}"/>
</f:facet>
<f:facet name="branch-closed">
<x:treeNodeIcon/>
<h:outputText value="#{node.description}"/>
</f:facet> <f:facet name="leaf">
<x:treeNodeIcon/>
<h:commandLink immediate="true" value="#{node.description}"/>
</f:facet> </x:tree>
Here is how I think it can be implemented:
<x:treeIconProvider> creates an instance of the specified IconProvider class. If there is an IconProvider specified, the tree renderer will take the current node and ask the IconProvider for the respective icon. The icon url will then be stored in a defined place (pageContext/request/...) where it can be found by the component created using the <x:treeNodeIcon> tag (a custom h:graphicImage component).
BTW, how are the icons in the example being displayed? I can't figureSorry, no trick, no secret :-) The icons are located in the /images/tree folder of the example web application and that's exactly the default location hard coded in the tree (see the initial values for iconLine, ... in HtmlTree). So you have to place the icons exactly at that location of define alternative icons using the tree tag.
it out. I'm assuming they are in the JAR file and you are using a
servlet trick to get at them. What is your secret?
Regards,
sean
-- Oliver Rossmueller Software Engineer and IT-Consultant Hamburg, Germany http://www.rossmueller.com

