Reputation: 2048
I am reading from the documentation on openlog:
Because Server-Side JavaScript Script Libraries have no context for which component called them, you will not be able to use this to pass the component to OpenLog. Instead, if you wish to identify which component called the code, you need to pass the component into your SSJS function as a parameter.
https://wiki.openntf.org/display/XOL/Using+from+SSJS+Script+Libraries
So I have a link which calls a SSJS function that resides in a script library:
<xp:link escape="true" text="#{obj.name}" rendered="#{obj.internal eq '3'}">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="dlgAssessment"> <xp:this.action><![CDATA[#{javascript:openDialogAssessment(this);}]]></xp:this.action> </xp:eventHandler> </xp:link>
The function registers failures to openlog as followed:
function openDialogAssessment(component){
try {
try{
assessmentBean.removeAssessment("assessment");
}catch(e){
openLogBean.addError(e,component);
}
//... more code
}
If I look at the log result in openlog I read:
null - Developer has passed 'this' directly from an SSJS function in Script Library /proposal.jss. Please note, SSJS Script Libraries have no context for components. You must pass the relevant component into your SSJS function as a parameter.
Can someone tell me what I am doing wrong and how I could pass the component to the function correctly?
Upvotes: 0
Views: 108
Reputation: 2635
In this context 'this' is the eventHandler. An eventHandler is not a UIComponent. You should pass 'this.getParent()' (the link) in this case.
Upvotes: 2
Reputation: 2048
As Ferry stated, this refers to a component, not the function. therefor the component should be provided to the ssjs function e.g. this.getParent().
Upvotes: 0