是否可以通过其类型获得控件集合,例如。标签,dojo控件喜欢编辑框,组合框等。通常,我想从extlib对话框中获取10个Label控件的集合。
感谢您的帮助。
答案 0 :(得分:3)
XPages是基于JSF构建的,所以是的。你从封闭元素开始(如果你想要所有的话,可以使用xp:view)并遍历子节点。类名是你要找的。 检查OpenNTF上的XPage Debug Toolbar项目以获取示例代码。
要明确:JSF在树中组织控件,因此您需要递归调用getChildren(),直到不再需要它们来获取所有这些控件。调试工具栏完成了所有这些,所以去获取源代码。
您正在查找的代码位于xpDebugToolbar脚本库中的getComponentIds()函数中。它最初是由Tommy Valand为他的API Inspector编写的。
答案 1 :(得分:1)
这是我的代码。
var myUtil = {
myArray : new Array(),
getComponentIDsByType : function(parentComp, parent, className) {
/*
parentComp: getComponent("controlId") or view for all
parent: null or parent of parentComp
className: class name of component
Example of usage:
wnUtil.getComponentIDsByType(getComponent("tableId"), null, "com.ibm.xsp.OutputLabel");
wnUtil.getComponentIDsByType(getComponent("tableId"), null, "com.ibm.xsp.extlib.dojo.form.FilteringSelect");
wnUtil.getComponentIDsByType(view, null, "com.ibm.xsp.extlib.dojo.form.FilteringSelect");
*/
var itr = parentComp.getChildren().iterator();
while(itr.hasNext()) {
var c:com.ibm.xsp.component.xp.XspScriptCollector = itr.next();
if(!parent) parent = parentComp;
var p = parentComp;
if(p && p.getId() && !p.getId().match(/^_id/i) && !p.getId().match(/^event/i) && !p.getId().match(/^selectItem/i) && !p.getId().match(/^dateTimeHelper/i) && !p.getId().match(/^br/i)) {
parent = parentComp;
}
if(c.getId() && !c.getId().match(/^_id/i) && !c.getId().match(/^event/i) && !c.getId().match(/^selectItem/i) && !c.getId().match(/^dateTimeHelper/i) && !c.getId().match(/^br/i) && !c.getId().match(/^typeAhead/i) && !c.getRendererType().equalsIgnoreCase('com.ibm.xsp.PassThroughTagRenderer')) {
//d.replaceItemValue("control", c.getId());
//if(parent) d.replaceItemValue("parent", parent.getId());
//d.replaceItemValue("type", this.getType(c.getRendererType()));
if (c.getRendererType() == className) {
//print (c.getId() + "<<<>>" + c.getRendererType());
// store component id to an array
this.myArray.push(c.getId());
}
}
this.getComponentIDsByType(c, parent, className);
}
}
}
然后你只需遍历myUtil.myArray