Cannot get XPages toolbar onItemClick event to execute when basicLeafNode contains onClick event

筅森魡賤 提交于 2019-12-11 13:44:21

问题


I have a toolbar with two basicLeafNodes in which I need to call some CSJS when they are clicked. To do this I put the CSJS in the onClick event of the basicLeafNode but when I do this, regardless of whether I return true, false or no return at all, the eventHandler for event="onItemClick" does not execute. If I remove the CSJS in the onClick event then onItemClick executes. Any ideas on what I am doing wrong here?

<xe:toolbar>
    <xe:this.treeNodes>
        <xe:basicLeafNode label="Back" submitValue="Back"></xe:basicLeafNode>
        <xe:basicLeafNode label="Save &amp; Back" submitValue="SaveAndBack" loaded="${javascript:document1.isEditable()}" onClick="console.log('save and back clicked');"></xe:basicLeafNode>
        <xe:basicLeafNode label="Edit" submitValue="Edit" loaded="${javascript:!(document1.isEditable())}"></xe:basicLeafNode>
        <xe:basicLeafNode label="Save" submitValue="Save" loaded="${javascript:document1.isEditable()}" onClick="console.log('save clicked'); return true;"></xe:basicLeafNode>
        <xe:basicLeafNode label="Delete"></xe:basicLeafNode>
    </xe:this.treeNodes>
    <xp:eventHandler event="onItemClick" submit="true" refreshMode="partial" refreshId="dc" disableValidators="#{javascript:context.getSubmittedValue() == 'Back'}">
        <xe:this.action>
            <![CDATA[#{javascript:
            vendor.runAction(context.getSubmittedValue(), document1);
        }]]></xe:this.action>
    </xp:eventHandler>
</xe:toolbar>

回答1:


basicLeafNode's onClick event overwrites toolbar's onItemClick event.

This is visible in rendered page source.

Just turn it around: add your client side actions into toolbar's onItemClick event.

You can get the clicked label with

        var node = thisEvent.target.parentNode;
        var label = node.getElementsByClassName('dijitButtonText')[0].innerHTML;

and add your code depending on clicked label.

Here is a working XPage example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xe:toolbar>
        <xe:this.treeNodes>
            <xe:basicLeafNode
                label="first"
                submitValue="first">
            </xe:basicLeafNode>
            <xe:basicLeafNode
                label="second"
                submitValue="second">
            </xe:basicLeafNode>
        </xe:this.treeNodes>
        <xp:eventHandler
            event="onItemClick"
            submit="true"
            refreshMode="complete">
            <xe:this.script><![CDATA[
                var node = thisEvent.target.parentNode;
                var label = node.getElementsByClassName('dijitButtonText')[0].innerHTML;
                alert('action for: ' + label);
                return true;
            ]]></xe:this.script>
            <xe:this.action><![CDATA[#{javascript:
                    print(context.getSubmittedValue());
            }]]></xe:this.action>
        </xp:eventHandler>
    </xe:toolbar>
</xp:view>


来源:https://stackoverflow.com/questions/37867543/cannot-get-xpages-toolbar-onitemclick-event-to-execute-when-basicleafnode-contai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!