Hi,
i want to add the JSF Component dynamically on click of Tree Node, i did it throgh some hard coding and it is working also,
MyTree.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:fs="myUri"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="tree2">
<a4j:outputPanel ajaxRendered="true">
<rich:panel id="treePanel">
<f:facet name="header">Charts</f:facet>
<rich:tree id="tree" ajaxSubmitSelection="true" switchType="ajax"
value="#{SelectionBean.rootNode}" var="node" nodeSelectListener="#{SelectionBean.addNewComponent}" reRender="grid1">
<rich:treeNode iconLeaf="/img/true.png" icon="/img/true.png">
<h:outputText value="#{node}"/>
</rich:treeNode>
</rich:tree>
</rich:panel>
</a4j:outputPanel>
</h:form>
|
<h:panelGrid styleclass="panelGrid" columns="3" binding="#{SelectionBean.grid}" id="grid1">
</h:panelGrid>
|
</ui:define>
</ui:composition>
SelectionBean.java:
public void addNewComponent(final NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
String nodeTitle = (String) tree.getRowData();
TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
FacesContext _context=FacesContext.getCurrentInstance();
if(nodeTitle.equals("Calendar"))
{
FacesMessages.instance().add("Chart 1 is Selected");
HtmlCalendar cal=new HtmlCalendar();
cal.setId(cal.getClientId(_context)+1);
grid.getChildren().add(cal);
}
if(nodeTitle.equals("CommandButton")){
HtmlCommandButton text1=new HtmlCommandButton();
text1.setValue("Adding the CommandButton ");
text1.setId(text1.getClientId(_context)+1);
grid.getChildren().add(text1);
}
if(nodeTitle.equals("Color Picker")){
HtmlColorPicker color=new HtmlColorPicker();
color.setId(color.getClientId(_context)+1);
grid.getChildren().add(color);
}
if(nodeTitle.equals("Chart")){
}
}
it is working fine, now i want to delete the component on select.
Can anybody help in this.
Thanks in advance
Regards
Devika.N