1

是否可以按其类型获取控件集合,例如。标签、dojo 控件喜欢编辑框、组合框等。总的来说,我想从 extlib 对话框中获取 10 个标签控件的集合。

感谢帮助。

4

2 回答 2

3

XPages 是建立在 JSF 之上的,所以是的。你从封闭元素(如果你想要所有的 xp:view)开始,然后遍历子元素。类名就是你要找的。检查 OpenNTF 上的 XPages 调试工具栏项目以获取示例代码。

需要明确的是:JSF 在树中组织控件,因此您需要递归调用 getChildren() 直到没有更多的东西来获取所有控件。调试工具栏完成了所有这些,所以去获取源代码。

您正在查找的代码位于 xpDebugToolbar 脚本库中的 getComponentIds() 函数中。它最初是由 Tommy Valand 为他的 API Inspector 编写的。

于 2012-12-29T02:20:50.320 回答
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

于 2013-01-10T18:41:22.630 回答