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 Reference tab.

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.




One response to “XPages Tip: Control Declaration Snippets”

  1. Sachin says :

    Wow ! Thank you for such an amazing tip !
    It works great with core controls,container controls, custom controls . The typed variables for ‘extension library’ components does not provide typeahead..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: