Generating a htmlTree dynamically
rchiarinelli.rchiarinelli.gmail.com Oct 31, 2008 4:43 PM
Hi All,
I'm developing a JSP, using RichFaces and Seam, which contains a htmlTree that is generated dynamically. But, my page doesn't show the htmlTree. Here is the snippet from JSP and the ManagedBean:
JSP:
.
.
.
<h:form id="treeMenuForm">
<rich:tree id="tree" binding="#{htmlTree}"/>
</h:form>
.
.
.
ManagedBean:
@Out(required = false)
private HtmlTree htmlTree;
@Begin(join = true)
@Factory(value = "htmlTree")
public HtmlTree getHtmlTree() throws ValidationException {
if (this.htmlTree == null) {
//HtmlTree
Application application = FacesContext.getCurrentInstance().getApplication();
this.htmlTree = (HtmlTree) application.createComponent(HtmlTree.COMPONENT_TYPE);
htmlTree.setStyle("width:300px");
htmlTree.setRendered(true);
htmlTree.setIcon("/image/Treeview/Treeview_folder_opened_A.gif");
htmlTree.setIconCollapsed("/image/Treeview/Treeview_plus_last_node.gif");
htmlTree.setIconExpanded("/image/Treeview/Treeview_minus_last_node.gif");
htmlTree.setIconLeaf("/image/Treeview/Treeview_page_A.gif");
htmlTree.setSwitchType("server");
htmlTree.setAdviseNodeOpened(application.createMethodBinding(
"#{mainViewAction.expanded}", new Class[0]));
htmlTree.setChangeExpandListener(application.createMethodBinding(
"#{mainViewAction.changeExpandListener}", new Class[0]));
htmlTree.getChildren().add(this.buildNodes(this.treeMenu));
}
return this.htmlTree;
}
/**
*
* @param nodes
* @return
*/
private HtmlTreeNode buildNodes(GBNode[] nodes) {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlTreeNode htmlTreeNode = null;
HtmlGraphicImage image = null;
HtmlOutputText text = null;
for (int cont = 0; cont < nodes.length; cont++) {
GBNode item = nodes[cont];
htmlTreeNode = (HtmlTreeNode) application.createComponent(HtmlTreeNode.COMPONENT_TYPE);
htmlTreeNode = new HtmlTreeNode();
htmlTreeNode.setId(viewRoot.createUniqueId());
htmlTreeNode.setRendered(true);
// Imagem do nó
image = (HtmlGraphicImage) application.createComponent(HtmlGraphicImage.COMPONENT_TYPE);
image = new HtmlGraphicImage();
image.setId(viewRoot.createUniqueId());
image.setHeight("18");
image.setWidth("15");
image.setStyleClass("textCurrentTreeview");
htmlTreeNode.getFacets().put("icon", image);
//Texto do nó
text = (HtmlOutputText)
application.createComponent(HtmlOutputText.COMPONENT_TYPE);
text = new HtmlOutputText();
text.setId(viewRoot.createUniqueId());
text.setValue(item.getText());
text.setStyleClass("textCurrentTreeview");
htmlTreeNode.getChildren().add(text);
}
return htmlTreeNode;
}
Can anyone help me?