Subscribe via Feed

Custom-Control 2 Custom-Control Communication

Lance Spellman, Jan 17, 2010 9:54:49 PM

I just got out of the very enlightening AD109 session on XPages performance and pigeonholed one of the speakers, Thomas McGuckin from the XPage development team.  There are a couple of things that I'd been scratching my head about that he helped clear up.

Let's say you have 2 custom controls on an XPage, A and B.  In custom control A, you have a field.  In custom control B, you have a computed field that has the server-side code:


The computed Field will never get set because it can't "SEE" the field in custom control A.  Why is this, and how do you get around it?

Think of the custom control as a container.  For custom control B, when getComponent is called, it operates within the context of that custom control.  Other custom controls are basically black boxes that it can't see into.  While that may sound unusual at first, it actually makes sense.  What if that custom control is inside a repeat control?  There's no way to guarantee the uniqueness of the id of that field.

Given that, it's not really appropriate to even try to phrase the approach in that way.  Instead, it was suggested to do 1 of three things.  For the field where the value is being set:

a.  put it in a scoped variable

b.  in Control B, access getDocument and grab the value from their (relevant where the control you're trying to get is for some data point).

c.  Create a custom property in Custom Control A, and set the value of the property from the control.  Custom Control B can see Custom Control A and access it's just can't see inside it.

Some worthwhile solutions to what was becoming a common problem for me.  However, while these are good solutions for accessing 'data', what if you really want to get a handle to a panel in the other custom control because you need to hide it for example.  None of these solutions really addresses that kind of requirement.

I'm sure someone brilliant here has a solution for this too.


5 responses to Custom-Control 2 Custom-Control Communication

Lenni Sauve, April 18, 2011 3:02 PM

Hi Lance!

Don't worry about replying to my question - IBM support found the answer in the Mastering xPages book. I'm still waiting for my copy to arrive!


Lenni Sauve, April 17, 2011 9:49 PM

Lance, I hope this doesn't sound goofy, but could you please explain how to accomplish item c in a little more depth?

I've been trying to pass the value of a computed field from one custom control to another and can't seem to get it to work.

When I create the Property Definition in the custom control with the field on it, if I select string as the Type, then I can see the property as a Custom property in the xPage for that custom control, however, if I try to set the value by using getComponent("EmployerID").getValue() because the EmployerID field does exist on that custom control, so it should be visible, I receive the error getComponent is null.

If I select DominoDocumentData as the Type for the Property Definition, as I think I should because I would be obtaining the value of a field on the document itself, the property does not display on the xPage for the custom control at all.

Where is my logic incorrect?

John Smart, March 23, 2010 5:55 AM


I was trying to do this same thing. I'm making a dialog that might be called from several places, so there's a one-to-many between my "dialogGuts" control and the several "dialogLaunchButton" controls, and was trying to figure out how the buttons will find the id of the dialog panel to tell it to open.

Now that I read your article, I'm instead going to use dojo.publish('/myApp/myDialog/OpenRequested') on the button controls, and use dojo.subscribe('/myApp/myDialog/OpenRequested', objectContainingHandlerMethod, stringNameOfHandlerMethod) within the dialog control's onload.

Which is really how I should have been trying it in the first place!

Vikas Tiwari, February 17, 2010 8:33 AM

Hi Lance,

I also faced the similar issue, then I found Dojo to the rescue. dojo.query saved lot's of time for me and is very reliable across browsers.
Let's say, we want to access a Panel with Id: "pnlTest" and at runtime Domino will generate id something like: "view:_id1:pnlTest".
Instead of worrying about getComponent() method, we can run dojo.query() to extract elements that end with "pnlTest".
var elem = dojo.query("[id$='pnlTest'")[0];

Another Sample code:
dojo.addOnLoad(function() {
var wl =dojo.query("a[id$='lnkProfileImage']")[0];
dojo.parser.parse(); });

I hope it helps.

Lenni Sauve, January 18, 2010 4:51 PM

Thanks so very much for that information Lance! This is exactly what I'm having problems with - knowing what items can 'see' what other items and how to work around that. Please do post anything further you find on this subject.