I have an xPage with multiple instances of the same custom control. How do I get to the value of a field on a specific custom control from a button on my xPage.
Normally I would do something like:
ctlName = "radioGroupCMBUAction"; var changeType = getComponent(ctlName).getValue();
If there was only one instance of the control. How would I do this with multiple instances of the control?
But I would rather not dynamically create an ID. I can't believe this is this hard to do. You would think I could just reference the custom control id to get to the individual controls - Bruce Stemplewski 2012-04-06 11:39
Without the code I'm not sure if .getValue() will work as in order for this to happen it will have to pull out a field where as a custom control could have a repeat inside it etc.
Assuming that it will work if each of the customControl instances have an id that is unique from each other it should work fine as each instance should have its own vriables inside it.
Other ideas however could be to pass in a string and use this string as the name of a scoped variable inside the custom control that can be pulled out from anywhere. I've done this before where I created a property on the custom control for a String and inside the custom control use
viewScope[compositeData.customProperty] = value.
then outside the context of the custom control I am aware of the string I passed in so I would be able to pull this value back out. Passing it in means multiple instances won't over write each other.
Or you could write the field in he custom control to a document, either to get it out or as the end solution to your problem of saving it.
eg.
<inputText id="sample">
then this will be turned into something like view:panel_34:control:sample
you can get at it by calling getComponent("sample");
If you need to interact with the field, my first thought is maybe more of this code should be inside the custom control its self, failing that I would do what I mentioned with the scoped variable and have that hold the id of the field so you could do getComponent(viewScope["control1"]) etc - Simon McLoughlin 2012-04-04 15:24
this can be very messy though, generally custom controls are best when there self containing, try putting validation inside it and anything else you need to make it so it can just be dropped on a page and pointed to a domino doc field or something like that, will be a lot easie - Simon McLoughlin 2012-04-04 15:28
Not sure if this can help you..? A while back, I wrote a tip regarding "private" scoped variables:
http://dontpanic82.blogspot.com/2010/03/xpages-tip-regarding-private-scoped.html