是否可以通过xPages API访问repeate控件内的面板?
这与我之前发布的问题有关 我正在尝试使用xPages API访问重复控件中的面板,但我没有成功,因为当我尝试获取重复控件的句柄并尝试通过其子级循环时,我只获取放置在面板中的表行和单元格,但我没有将面板作为重复的子级。下面是我用来执行此操作的代码。请建议是否有任何其他方式访问重复内的面板。我需要这样才能访问面板中的数据源以单独保存它们是否可以通过xPages API访问repeate控件内的面板?,xpages,panel,repeat,Xpages,Panel,Repeat,这与我之前发布的问题有关 我正在尝试使用xPages API访问重复控件中的面板,但我没有成功,因为当我尝试获取重复控件的句柄并尝试通过其子级循环时,我只获取放置在面板中的表行和单元格,但我没有将面板作为重复的子级。下面是我用来执行此操作的代码。请建议是否有任何其他方式访问重复内的面板。我需要这样才能访问面板中的数据源以单独保存它们 function getComponentValueInRepeat(strRepeatID, strCompID, tmpRowIndex) { var repe
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...");
}
函数getComponentValueInRepeat(strRepeatID、strCompID、tmpRowIndex){
var repeatComp:com.ibm.xsp.component.UIRepeat=getComponent(strRepeatID);
var-rowIndex=1;
如果(null!=重复编译){
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();
}
对于(ComparlLoopCont=0;ComparlLoopCont
在处理数据时,您应该始终尝试跟踪数据,而不是用户界面。更改用户界面时,逻辑会中断。您的任务有许多选项:
- 将单个保存按钮放在面板中,然后使用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);
}
当然,另一种方法是使用一个bean作为具有getApprovals(数据库)的页面的对象数据源初始化它的函数使用
xp:repeat
和xp:panel
的XPage源编辑您的问题,这将有助于更好地理解您的问题。您好,Naveen重复和panel的代码已在我的上一个问题中给出,我已在这个问题中提供了链接(需要知道如何在重复控件中的文档集合中标记字段)最有可能的是,你正在尝试做一些比你所要求的解决方案更好的事情。从“我想如何解决它”中退一步,并解释:目的是什么。如果解决方案不容易掌握,你的方法需要重新考虑,那么经常会问重复的概念。重复的孩子只存在一次。重复的孩子只存在一次repeat的工作是重复处理同一组子项。因此,例如,你无法获得repeat中的第三个面板,因为只有一个面板会被反复处理。更好的方法是创建一个数据模型层并将你的repeat绑定到该层;举个例子,请参考以下答案:然后你可以直接对话无需搜寻组件即可访问数据。