Reputation: 1
I have a web page with dojo code on it, including a function passed to dojo.addOnLoad with the following code:
laborDetailHandler.RevenueTotalInput = dojo.byId('#{id:LaborRevenueTotal}');
if (!laborDetailHandler.RevenueTotalInput) {
console.warn('RevenueTotalInput not found.')
}
If this code is in-line, even if it's above the LaborRevenueTotal inputbox, it works.
If this code is moved out to a script library, I get the 'RevenueTotalInput not found.' message, which tells me that dojo.addOnLoad receives the function and executes it, but for some reason the function isn't working.
I'm completely stumped here. Anyone have any ideas?
Upvotes: 0
Views: 442
Reputation: 15739
If you put code in a property or event on an XPage, it gets passed as a String and through an evaluator. If you look at the Java classes created for your XPages in the Package Explorer view, you'll see what I mean. The code is a String that is then passed to a Java function that evaluates it on page load or at runtime.
I don't think code in the Script Libraries goes through the evaluator, so the #{id:myField} isn't calculated. There is also the issue of the context from which to identify which myField on your rendered HTML page it means.
There are two ways round it. One is to pass the ID into your SSJS / CSJS functions from your XPage events. The other option in CSJS is to use dojo.query.
Upvotes: 1
Reputation: 3355
Although script libraries are not compiled in XPages; they also don't run inline.
The best practice in XPages is using black-box approach in script libraries. Use parametrization for all functions defined in script libraries (valid for both server-side and client-side).
In SSJS, alternatively, you may get the component objects by getComponent and learn their client-id's however, this reduces the reusability of script libraries. It's fine if you use them just to keep your XSP code clean; but make sure using error traps (try/catch) because it's an headache to debug SSJS.
Upvotes: 0
Reputation: 3524
'#{...}' expression does not work inside SSJS libraries, only in source of XPage or Custom Control.
Workaround: use #{} clause anywhere else (text field, for example) and refer to it in your client side script.
Upvotes: 2
Reputation: 1
I apologize! I thought this was a dojo question; instead it was a Lotus Notes XPages question! I'm still not sure why this is happening, but someone has corroborated the that problem is larger than my script and how to resolve it.
My workaround is, rather than find these elements within the script library, to get handles to the elements I need and pass them to an initialize function within the script library.
Thank you very much peller for responding. I'm sorry my question was bad.
Upvotes: 0