1

我在 xpage 上有一个计算字段,其结果是 HTML。在该 HTML 中,我想计算一个链接,该链接将触发一些服务器端 js 函数,然后进行部分刷新。

我当前的代码如下所示:

<a href="#" onclick="return myFunction()">Click Here</a>

如果我的 js 函数是客户端函数,这将起作用,但我想使用此函数来设置文档上字段的值,所以我需要 SSJS。

从 xpage 中的控件托盘创建的静态链接允许链接通过部分刷新调用 SSJS。如何使用计算出的 HTML 链接做到这一点?

4

3 回答 3

3

另一种选择可能是创建您自己的事件处理程序并通过本文中描述的客户端 JavaScript 代码执行它。因此,假设您创建了一个类似这样的事件处理程序:

<xp:eventHandler event="name" id="eventhandler1a">
    <xp:this.action>
        <xp:saveDocument />
    </xp:this.action>
</xp:eventHandler>

然后,您可以创建一个函数来通过 JavaScript 代码调用此事件处理程序:

XSP.executeOnServer = function () {
    // the event handler id to be executed is the first argument, and is required
    if (!arguments[0])
        return false;
    var functionName = arguments[0];

    // OPTIONAL - The Client Side ID that is partially refreshed after executing the event handler
    var refreshId = (arguments[1]) ? arguments[1] : "@none";
    var form = (arguments[1]) ? this.findForm(arguments[1]) : dojo.query('form')[0];

    // catch all in case dojo element has moved object outside of form...
    if (!form)
        form = dojo.query('form')[0];

    // OPTIONAL - Options object containing onStart, onComplete and onError functions for the call to the
    // handler and subsequent partial refresh
    var options = (arguments[2]) ? arguments[2] : {};

    // OPTIONAL - Value to submit in $$xspsubmitvalue. can be retrieved using context.getSubmittedValue()
    var submitValue = (arguments[3]) ? arguments[3] : '';

    // Set the ID in $$xspsubmitid of the event handler to execute
    dojo.query('[name="$$xspsubmitid"]')[0].value = functionName;
    dojo.query('[name="$$xspsubmitvalue"]')[0].value = submitValue;
    this._partialRefresh("post", form, refreshId, options);
}

然后,您可以通过此客户端 JavaScript 代码调用事件处理程序:

XSP.executeOnServer('#{id:eventhandler1a}', '#{id:panel1}')

这里panel1指的是部分刷新的控件。

于 2013-10-25T03:54:11.917 回答
1

链接控制不是静态的。你可以计算任何你想要的,例如:

<xp:link escape="true" id="lnk">
   <xp:this.value><![CDATA[#{javascript:"#"}]]></xp:this.value>
   <xp:this.text><![CDATA[#{javascript:"Label here"}]]></xp:this.text>
</xp:link>
于 2013-10-24T21:05:22.763 回答
1

如果您在客户端函数中使用XSP对象,您可以坚持使用您的代码。myFunction()这允许您调用部分刷新。另一种选择是调用 Extlib JSON 控件并在那里设置您的逻辑。取决于您的编码风格

于 2013-10-24T23:30:45.310 回答