另一種選擇,可以創建自己的事件處理程序,並執行它通過客戶端的JavaScript代碼在這個article描述了一點。因此,假設您創建事件處理程序是這樣的:
<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
是指以控制這將是部分地刷新。
這很有意義,但我仍然無法弄清楚如何獲取我在客戶端JS中設置的值。我想在部分刷新之後在面板上使用事件,但onClientLoad事件不會在部分刷新時觸發。我嘗試使用Naveen建議的方法(以及您的XSP對象後),但無法找出使用context.getSubmittedValue的位置,因爲我沒有從SSJS觸發此代碼開始。我想獲取我在CSJS中設置的值,並在部分刷新面板之前使用它來更改後端。 –
context.getSubmittedValue()是SSJS,用於通過部分刷新觸發的代碼。例如。當你刷新面板時,你可以把它放在裏面的任何元素中。專業提示:它可以有HTML參數:style:visibility:hidden – stwissel
完美。這幫了很多。謝謝! –