如何为rich:tree不同类型节点设置右键菜单

组合使用targettargetSelector就可以啦,如下: <rich:tree id="ruleTree" value="#{treeAction.ruleTree}" var="node" nodeType="#{node.type}"
    selectionChangeListener="#{treeAction.selectTreeNode}" toggleType="client"
    selectionType="ajax">
    <rich:treeNode type="CATEGORY" styleClass="categoryTag">
        <h:outputLabel value="#{node.name}">
            <a4j:ajax event="click" execute="@this" render="propCol"/>
        </h:outputLabel>
    </rich:treeNode>
    <rich:treeNode type="CONDITION" styleClass="conditionTag">
        <h:outputLabel value="#{node.name}">
            <a4j:ajax event="click" execute="@this" render="propCol"/>
        </h:outputLabel>
    </rich:treeNode>
    <rich:treeNode type="RULE" styleClass="ruleTag">
        <h:outputLabel value="#{node.name}">
            <a4j:ajax event="click" execute="@this" render="propCol"/>
        </h:outputLabel>
    </rich:treeNode>
</rich:tree>

<rich:contextMenu id="categoryMenu" target="ruleTree" targetSelector=".categoryTag" mode="ajax">
    <rich:menuItem label="#{messages['button.addCondition']}"/>
    <rich:menuItem label="#{messages['button.addRule']}"/>
    <rich:menuItem label="#{messages['button.delete']}"/>
</rich:contextMenu>

<rich:contextMenu id="conditionMenu" target="ruleTree" targetSelector=".conditionTag" mode="ajax">
    <rich:menuItem label="#{messages['button.addCondition']}"/>
    <rich:menuItem label="#{messages['button.addRule']}"/>
    <rich:menuItem label="#{messages['button.copyPaste']}"/>
    <rich:menuItem label="#{messages['button.delete']}"/>
</rich:contextMenu>

<rich:contextMenu id="ruleMenu" target="ruleTree" targetSelector=".ruleTag" mode="ajax">
    <rich:menuItem label="#{messages['button.copyPaste']}"/>
    <rich:menuItem label="#{messages['button.delete']}"/>
</rich:contextMenu>

你可能感兴趣的:(contextMenu,tree,Richfaces)