This is how I get stuff into the tree:
| package adapters;
|
| import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
| import org.apache.myfaces.trinidad.model.TreeModel;
|
| import java.util.Collection;
|
| /**
| * Wraps a nested tree of nodes into a Trinidad TreeModel.
| *
| * The primary purpose of this adapter is to check if a node has children,
| * or not. The wrapped TreeModel then results in correct rendering of the
| * tree, either as a container or a node icon.
| *
| * See faces-config.xml for a usage example.
| *
| * @author Christian Bauer
| */
| public class TreeModelAdapter {
|
| private Collection rootCollection;
| private String childCollectionPropertyName;
|
| public TreeModelAdapter() {}
|
| public TreeModel getTreeModel() {
| return new ContainerAwareChildPropertyTreeModel(rootCollection,
childCollectionPropertyName);
| }
|
| public Collection getRootCollection() {
| return rootCollection;
| }
|
| public void setRootCollection(Collection rootCollection) {
| this.rootCollection = rootCollection;
| }
|
| public String getChildCollectionPropertyName() {
| return childCollectionPropertyName;
| }
|
| public void setChildCollectionPropertyName(String
childCollectionPropertyName) {
| this.childCollectionPropertyName = childCollectionPropertyName;
| }
|
| /**
| * This inner class extends the built-in Trinidad TreeModel, which by
default
| * treats every node as a container. Users have to click on a node to
see
| * if there is something in the container, and the rendering is also
wrong.
| * This might trigger loading of the children (the collection of
children is
| * touched) if you have lazy loading. However, you now get correct
rendering
| * of nodes and a regular node does no longer appear as a container.
| */
| class ContainerAwareChildPropertyTreeModel extends
ChildPropertyTreeModel {
|
| public ContainerAwareChildPropertyTreeModel(Object object, String
string) {
| super(object, string);
| }
|
| public ContainerAwareChildPropertyTreeModel() {
| super();
| }
|
| public boolean isContainer() {
| boolean hasChildren = false;
| // Hit the children collection of this container to
| // figure out if its really a container
| enterContainer();
| if (getRowCount() > 0) hasChildren = true;
| exitContainer();
|
| return hasChildren;
| }
| }
| }
|
| <faces-config>
|
| <!-- JSF backing beans that call Seam components, these
| backing beans provide an additional layer between
| business components managed by Seam and presentation-only
| beans. Common backing beans in a Seam application are
| model adapters (that convert from a java.util.Collection
| to a Trinidad TreeModel, for example).
| -->
| <managed-bean>
| <managed-bean-name>catalogCategoryAdapter</managed-bean-name>
| <managed-bean-class>adapters.TreeModelAdapter</managed-bean-class>
| <managed-bean-scope>request</managed-bean-scope>
| <managed-property>
| <property-name>rootCollection</property-name>
| <value>#{catalog.rootCategories}</value>
| </managed-property>
| <managed-property>
| <property-name>childCollectionPropertyName</property-name>
| <value>childCategories</value>
| </managed-property>
| </managed-bean>
| ...
|
I guess I should use a Seam component for this last bit, instead of a dumb JSF
backing bean.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979032#3979032
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979032
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user