Getting a field value from a custom control when there are multiple instances of the custom control

巧了我就是萌 提交于 2019-12-14 03:10:39

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/10001442/getting-a-field-value-from-a-custom-control-when-there-are-multiple-instances-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!