rich tree and a4j support onselected - how to?
j-pro Oct 17, 2007 1:28 PMGood afternoon.
My point is to make update a form on a page after user clicks on a tree node.
I tried two ways, none of it worked:
The first one:
<rich:tree style="width:250px" id="structureTree" styleClass="tree" switchType="ajax" ajaxSubmitSelection="true" showConnectingLines="true" changeExpandListener="#{treeMan.onDepartmentTreeExpand}" nodeSelectListener="#{treeMan.onDepartmentTreeSelect}" stateAdvisor="#{departmentTreeStateAdvisor}"> <rich:recursiveTreeNodesAdaptor roots="#{treeMan.departmentsTreeRoots}" var="item" nodes="#{item.nodes}" /> <a4j:support event="onselected" actionListener="#{treeMan.onA4JDepartmentTreeSelect}" reRender="pretendersDataTable_Form"/> </rich:tree>
public void onA4JDepartmentTreeSelect(ActionEvent event) { UITree tree = (UITree) event.getComponent(); DepartmentTreeNode selectedNode = (DepartmentTreeNode)tree.getRowData(); ... }
And all I'm getting after clicking on a node, is this:
actionListener="#{treeMan.onA4JDepartmentTreeSelect}": java.lang.ClassCastException: org.ajax4jsf.component.html.HtmlAjaxSupport
This exception is caused by this line: "UITree tree = (UITree) event.getComponent();"
Then I've tried the second way, like it was done with HtmlDataTable(using binding to UITree property):
<rich:tree style="width:250px" id="structureTree" styleClass="tree" switchType="ajax" ajaxSubmitSelection="true" showConnectingLines="true" changeExpandListener="#{treeMan.onDepartmentTreeExpand}" nodeSelectListener="#{treeMan.onDepartmentTreeSelect}" stateAdvisor="#{departmentTreeStateAdvisor} binding="#{treeMan.tree}"> <rich:recursiveTreeNodesAdaptor roots="#{treeMan.departmentsTreeRoots}" var="item" nodes="#{item.nodes}" /> <a4j:support event="onselected" actionListener="#{treeMan.onA4JDepartmentTreeSelect}" reRender="pretendersDataTable_Form"/> </rich:tree>
And my action listener method changed to:
... private UITree tree; ... public void onA4JDepartmentTreeSelect(ActionEvent event) { // commented because of private property UITree tree //UITree tree = (UITree) event.getComponent(); DepartmentTreeNode selectedNode = (DepartmentTreeNode)tree.getRowData(); ... }
And this time I'm getting this:
actionListener="#{treeMan.onA4JDepartmentTreeSelect}": java.lang.IllegalStateException: No tree element available or row key not set!
This exception is caused by this line: "DepartmentTreeNode selectedNode = (DepartmentTreeNode)tree.getRowData();"
Please, help me to understand what should be done to make this work? I already learned how to catch clicks on nodes using nodeSelectListener, but using it I can't reRender needed regions on the page. The one and only way for it is a4j:support with reRender attribute. But how make it work? I'm sure I'm doing something wrong, so please, point me to the right direction.
Thanks in advance!