XPages Tip: Control Declaration Snippets
Control Declaration Snippets give you an easy way to retrieve a properly-typed handle to an XPages control on your page. In this post, I’ll show how to use them and why they are beneficial.
Control Declaration Snippets
From the SSJS script editor, Control Declaration Snippets is one of the
Libraries: options on the
It displays an alphabetized list of controls on the page.
Double-click any one to insert the control declaration snippet into your script.
This screen shot shows the result of adding snippets for all 7 controls on my sample page:
This is a convenient way to save a few keystrokes in setting up a handle to a control on your page, but that’s not the only benefit.
Normally, when you set up a variable for a handle to a control, you don’t enter the full data type of that control. Control declaration snippets do that for you. The big advantage is that typed variables provide better typeahead.
Take, for example, these two lines, which accomplish the same thing:
var myInputText = getComponent("inputText1"); var inputText1:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
If you type
myInputText. you’ll get some typeahead options because the editor knows that you’re dealing with a some component.
However, if you type
inputText1. you’ll get many more typeahead options (including event handlers) because the editor now knows exactly what type of component that you’re working with.