Tuesday, December 1, 2009

Server side event handling - get value without having to use getComponent

If you type this.getParent().getValue(), you will get the value of the component that holds the event handler.

this.getParent() returns the component that holds the event handler.

this is the EventHandler object.

3 comments:

Thomas Adrian said...

Hello Tommy,

I have a repeat control in a custom control. do you know if it is possible to access the values programmatically in the repeat control from an xpage?

Let's say my repeat control is looping a view and I want from my xPage return the title of one of the documents in the repeat control.

the most logical would be to navigate down i.e:
getComponent("myCustomControl").getComponent("myrepeat").getFirst().. etc but it does not seem to work that way.



Thanks
Thomas

Tommy Valand said...

Have you tried something like this (computed dynamically):
var items = getComponent("myrepeat").getFacetsAndChildren(); // returns an Iterator

var item;
while( items.hasNext() ){
item = items.next();
/* Test to see if item is the component type you're looking for -> fetch the value/etc */
}

To find the correct datatype (using typeof), you can use a "debug function". I send a mail to myself when I debug. It's probably not the most effective debug-method, but it works ok..

function debug( message ){
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue( 'Form', 'Memo' );
doc.replaceItemValue( 'Subject', 'Debug..' );
doc.replaceItemValue( 'Body', message.toString() );
doc.replaceItemValue( 'SendTo', 'mail@domain.com' );
doc.send()
}

E.g. debug( typeof getComponent('someId') );

Thomas Adrian said...

thanks, don't really know how to get the value though, there must be a simpler way.

well, I hope all developers out there understand the consequence of putting controls inside a custom control. you will have a hard time accessing its values from outside the CC.

I have blogged about this before here (in swedish) http://xpages.notessidan.se/blogg.nsf/xstart.xsp?post=1710D16D064853BEC1257671005134BE

it is easy to access values from a CC to a Xpage, but not the other way around.

I hope IBM will document this strange relation soon.