Wednesday, May 9, 2012

Pass server side javascript code to custom control

Some time back I was trying to pass server side javascript to a custom control and then get the code executed from click of a button inside the custom control. With help from Sven Hasselbach I was able to do it. But the problem in that approach was that your entire code has to written in a string literal which denies you the flexibility of the javascript editor. Experimenting a bit more I stumbled on another solution which I think is better.

For custom control property select Type as "Simple Actions > Execute Script".

This would set the Type as Keep the Editor for the property as blank.

Now when you add the custom control to an XPage the property will show up with two attributes - loaded & script. In XPage source you will get <xp:executeScript> tag inside the custom control.

Add your code in the script attribute. To execute your code inside custom control use the following code:

And you are done!

No comments:

Post a Comment