是否可以通过xPages API访问转发器控件内的面板?

时间:2013-12-17 11:17:14

标签: xpages panel repeat

这引用了我之前发布的问题Need to know the way to stamp a field within a document collection which is in a repeat control

我正在尝试使用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...");
}

1 个答案:

答案 0 :(得分:2)

处理数据时,您应始终尝试追踪数据,而不是UI。你改变你的UI,你的逻辑中断。您的任务有多种选择:

  • 将单独的保存按钮放在面板中。然后document1.save()将很好地完成这个技巧
  • 将文档的ID保存在viewScope变量中,当某些操作需要保存文档时,请使用该值来确定文档(可能是杂乱的)
  • 不绑定到文档,将值绑定到自定义对象的集合。这些对象由重复控制逻辑填充并存储在viewScope中。当您点击保存按钮时,所有更改的值都会被提交,您可以在设置器中定义标记“我是否需要保存”并保存。

课程看起来像这样:

  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);
 }

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