Tree
The jp:tree component can be used for the hierarchical representation of data with a flexible number of hierarchy levels. Each scope of hierarchies need to be implemented as a TreeHandler extended the SbTreeXHander where X is the hierarchy level.
In the example the JeeCmsTreeHandler is implementing a two-level structure. The super-constructor has to be called with three parameters:
- JeeslTreeSelected : This is a callback object which is called after a selection
- JeeslTreeCache : This object is handling the child elements for each level, mostly implemented in a cache.
- JeeTreeStore : This object allows storing of selections e.g. in a session Bean. In the init -method of the JeeskTreeHandler the previously selected element can be retrieved.
In the given example the JeeslTreeCache and JeeTreeStore are created in the constructor for simplicity. In production environment often AppScoped (for the cache) and SessionScoped (for the store) beans are provided.
A good starting point for a own implementation
- of SbTree2Handler is to assume a global view and ignore security aware views and/or domain roles on the specific hierarchy levels.
- of JeeslTreeCache is to directly use facade methods.
- of JeeTreeStore is to do nothing
Start with a two-level hierarchy and then extend it!
<jp:sbTree handler="#{sbTreeBean.sbhTree}" update="@form :grid"/>
@Named @ViewScoped
public class SbTreeBean extends AbstractJeeBean implements JeeslSbTreeBean
{
final static Logger logger = LoggerFactory.getLogger(SbTreeBean.class);
private static final long serialVersionUID = 1L;
private JeeSbTreeCmsHandler sbhTree; public JeeSbTreeCmsHandler getSbhTree() {return sbhTree;}
@PostConstruct
public void init()
{
super.initSecurity();
sbhTree = JeeSbTreeCmsHandler.instance(this,fUtils).debugOnInfo(true);
sbhTree.update();
// update() at the end of @PostsConstruct, because it's calling sbTreeSelected
}
@Override public void sbTreeSelected()
{
logger.info("Selected");
sbhTree.debug(true);
}
}
Resource not found:
/jeesl/java/org/jeesl/showcase/controller/handler/tree/JeeCmsHierarchyHandler.java
must be available in the classpath
Resource not found:
/jeesl/java/org/jeesl/showcase/controller/handler/tree/JeeTreeCmsCache.java
must be available in the classpath
Resource not found:
/jeesl/java/org/jeesl/showcase/controller/handler/tree/JeeTreeCmsStore.java
must be available in the classpath