是否可以通过xPages API访问中继器控制内部的面板



这引用了我之前发布的问题需要知道在重复控制中的文档集合中标记字段的方法

我正在尝试使用xPages API访问重复控件中的面板,但我没有成功,因为当我尝试获取重复控件的句柄并尝试循环其子控件时,我只获取放在面板中的表行和单元格,但我无法将面板作为重复的子控件。这是我使用的代码。请建议是否有其他方法可以访问重复中的面板。我需要访问面板中的数据源以单独保存它们。

function getComponentValueInRepeat(strRepeatID, strCompID, tmpRowIndex) {
var repeatComp:com.ibm.xsp.component.UIRepeat = getComponent(strRepeatID);
var rowIndex = 1;
if (null != repeatComp) {
    var repeatList:java.util.Iterator = repeatComp.getFacetsAndChildren();
    var repeatContainer:com.ibm.xsp.component.UIRepeatContainer = null;
    var entityComponent:javax.faces.component.UIComponent = null;
    while (repeatList.hasNext()){
        repeatContainer = repeatList.next();
        var componentList = repeatContainer.getChildren();
        while (componentList.length == 1 && 
                (componentList[0].getClass().getName().equals("com.ibm.xsp.component.xp.XspTable") |
                componentList[0].getClass().getName().equals("com.ibm.xsp.component.xp.XspTableRow"))) {
            componentList = componentList[0].getChildren();
        }
        for (compArrLoopCont = 0 ; compArrLoopCont < componentList.length; compArrLoopCont++) {
            entityComponent = componentList[compArrLoopCont];
            if (entityComponent.getChildCount() == 1 && 
                    entityComponent.getClass().getName().equals("com.ibm.xsp.component.xp.XspTableCell")) {
                entityComponent = entityComponent.getChildren();
                entityComponent = entityComponent[0];
            }
            if (entityComponent.getId().equals(strCompID) && tmpRowIndex == rowIndex) {
                if (null == entityComponent.getValue()) {
                    return "";
                } else {
                    return entityComponent.getValue();
                }
            }
        }
        //print ("hello +++ " + entityComponent[0].getId());
        rowIndex++;
    }
} else {
    print ("exception...");
}

在处理数据时,您应该始终关注数据,而不是UI。你改变了你的用户界面,你的逻辑就崩溃了。您的任务有许多选项:

  • 将单个保存按钮放在面板内。然后一个document1.save()就能很好地完成任务
  • 将文档的ID保存在viewScope变量中,当某些操作需要保存文档时,使用该值来确定文档(可能很混乱)
  • 不要绑定到文档,而是将值绑定到自定义对象的集合。这些对象由重复控制逻辑填充并存储在viewScope中。当你点击保存按钮时,所有更改的值都会被提交,在你的setter中,你可以定义标志"我需要保存吗"并保存它

这个类可能看起来像这样:

  public class Approval() {
      private boolean isDirty = false;
      private final String unid;
      private String approver;
      // more fields here;
      public Approval(String unid, String approver /* more values or pass the NotesViewEntry */) {
          this.unid = unid;
          this.approver = approver;
      }
      public String getUnid() {
          return this.unid;
      }
      public String getApprover() {
          return this.Approver;
      }
      public void setApprover(String newApprover) {
             if (!this.approver.equals(newApprover)) {
                this.isDirty = true;
             }
             this.approver = newApprover;
      }
      public void save(Database db) {
           if (!this.isDirty) {
              return; // No action needed
           }
           Document doc = db.getDocumentByUnid(this.unid);
           doc.replaceItemValue("Approver",this.approver);
           doc.save();
      }
  }

所以你的重复代码看起来像这样:

// If we looked them up before we don't need to do anything
if (viewScope.approvals) {
    return viewScope.approvals;
}
// Look up the employee details view to get the employee appraisal details from the current database
var curDB:NotesDatabase = session.getCurrentDatabase();
var vwlkApprView:NotesView = curDB.getView("vwlkAllApprApper");
var collDocAppr:NotesViewEntryCollection = vwlkApprView.getAllEntriesByKey(sessionScope.EmployeeID);
// Don't do a count, slow!
var result = new java.util.Vector();
// Add all approvals
var ve:NotesViewEntry = collDocAppr.getFirstEntry();
while (ve != null) {
   var nextVe = ve.getNextEntry(ve);
   // make this next line nicer!
   result.add(new demo.Approval(ve.getUniversalid(),ve.getColumnValues().get(0))); // eventually check to avoid categories?
   ve.recyle();
   ve = nextVe;
}
viewScope.approvals = result.isEmpty() ? null : result;
collDocAppr.recyle();
vwlkApprView.recycle();
return viewScope.approvals;

然后,您的保存按钮将循环通过收集

 for (var a in viewScope.approvals) {
    a.save(database);
 }

当然,另一种方法是让一个bean作为页面的对象数据源,该页面具有getApprovals(数据库)函数来初始化它

最新更新