Search code examples
jsfrichfaces

rich faces selectionChangeListener for two different column


I have a richtree like this :

<rich:tree id="positionTree"
                           value="#{positionAdminBean.positionTree}"
                           var="pos" switchType="ajax" binding="#positionAdminBean.htmlTree}"
                           nodeSelectListener="#{positionAdminBean.onCmdSelectPosition}"
                           ajaxSubmitSelection="true" reRender="positionPanel,mainTabbedPane,selectGroupPanel">
<rich:treeNode id="treeNodeId">
                        <table width="100%">
                            <tr>
                                <td width="50%">
                                    <h:outputText value="#{pos.name}" id="treeposNameId"/>
                                </td>
                                <td width="40%">
                                    <h:outputText value="#{pos.humanResourceName}" id="treeposHumanResName"/>
                                </td>
                            </tr>
                        </table>
                    </rich:treeNode>
                </rich:tree>

these codes generate and show a tree of data correctly. but my problem is that when you click on a row it fires nodeSelectListener="#{positionAdminBean.onCmdSelectPosition}".

as you see my tree has two columns , I need to do something with this code that every columns has its own select listener . or do something that when user click on each columns it does different works


Solution

  • Well, a nodeSelectListener is fired when a node is selected. You can not assign it to something that is only a part of the node.

    You can define an <a4j:jsFunction> and call it when the table cell is clicked.

    <a4j:jsFunction name="firstColumnListener" actionListener="#{bean.doSomething}" … >
        <a4j:param name="id" assignTo="#{bean.selectedId}" />
    </a4j:jsFunction>
    
    <td onclick="firstColumnListener(id)">
        …
    </td>