Onclick event in Outline gets executed on page open

放肆的年华 提交于 2019-12-20 04:58:25

问题


I have an extension library outline control. I have two basicLeafNodes in the outline. The onclick event on each of these nodes is supposed to run some code. The problem is both of those onClick events are being executed when the page is open but does not seem to execute when you actually click on the node.

Any idea what could be wrong?

<xe:outline id="outline1">

<xe:this.treeNodes>
        <xe:basicLeafNode label="Set Value 1">
            <xe:this.onClick><![CDATA[#{javascript:getComponent("inputText1").value = "123";}]]></xe:this.onClick>
        </xe:basicLeafNode>
        <xe:basicLeafNode label="Set Value2">
            <xe:this.onClick><![CDATA[#{javascript:getComponent("inputText2").value = "456";}]]></xe:this.onClick>
        </xe:basicLeafNode>
    </xe:this.treeNodes>

</xe:outline>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>Value 1:&#160;
<xp:inputText id="inputText1"></xp:inputText>
<xp:br></xp:br>Value 2:&#160;
<xp:inputText id="inputText2"></xp:inputText>

回答1:


The onClick event of the basicLeafNode is for client-side JS only. You need to use the submitValue property of each basicLeafNode to and then add SSJS to the onItemClick event of the outline control. You can then use context.getSubmittedValue() to check what node was clicked and then act accordingly:

<xe:outline id="outline1">
    <xe:this.treeNodes>
        <xe:basicLeafNode label="Set Value 1" submitValue="1"></xe:basicLeafNode>
        <xe:basicLeafNode label="Set Value2" submitValue="2"></xe:basicLeafNode>
    </xe:this.treeNodes>
    <xe:this.onItemClick><![CDATA[#{javascript:
        if (context.getSubmittedValue() == "1") {
            getComponent("inputText1").value = "123"
        } else if (context.getSubmittedValue() == "1") {
            getComponent("inputText2").value = "456"
        }
    }]]></xe:this.onItemClick>
</xe:outline>

From the XPages Extension Library book (page 240):

The onClick property allows the developer to execute a piece of Client-Side JavaScript code, and the submit- Value property allows the developer to specify a value that is passed back to the server. This value is accessed from the onItemClick event of the control that contains the tree nodes.



来源:https://stackoverflow.com/questions/14758208/onclick-event-in-outline-gets-executed-on-page-open

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