我想通过触发xpage上的按钮点击事件来测试java代理以清除视图中的所有文档。我在java代理中没有错误,但它无法正常工作。你能帮助我度过这个阶段吗?
按钮点击事件:
var serverName=session.getCurrentDatabase().getServer();
//@WarningMessage("current one");
//@WarningMessage("server=" + serverName);
//var db:NotesDatabase = session.getDatabase(session.getCurrentDatabase().getServer(), "\ProTexII.nsf");
var db:NotesDatabase=session.getCurrentDatabase();
@WarningMessage("db=" + db);
var agent:NotesAgent = db.getAgent("SnapShotUpdate");
@WarningMessage("agent" + agent);
if (agent!=null){
agent.run();
@WarningMessage("view is fired!");
}
Java代理:
package javaPkg;
import java.io.PrintWriter;
import lotus.domino.*;
public class SnapShotUpdate extends AgentBase{
public void NotesMain() {
try {
//String p = session.getPlatform();
//PrintWriter out=getAgentOutput();
System.out.println("Hello i never give it up!!");
Session session = getSession();
AgentContext agentContext =session.getAgentContext();
Database db=session.getCurrentDatabase();
//**clear view "vActualSalesFromSD" before copying documents into it
DocumentCollection dc= db.createDocumentCollection();
View view= db.getView("vActualSalesFromSD");
Document docToBeCleared= view.getFirstDocument();
while (docToBeCleared != null) {
{
dc.addDocument(docToBeCleared);
}
docToBeCleared = view.getNextDocument(docToBeCleared);
}
dc.removeAll(true);
} catch(Exception e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:5)
您有3种触发代码的可能性:
可能出现的问题:
我会写这样的循环:
public function clearView(Database db, String vName ) {
try {
View view= db.getView("vActualSalesFromSD");
Document docToBeCleared= view.getFirstDocument();
Document nextDoc = null;
while (docToBeCleared != null) {
nextDoc = view.getNextDocument(docToBeCleared);
try {
docToBeCleared.remove(true);
} catch (Exception didntWork) {
// Do some logging here
}
// Recycle your objects
doc.recycle();
docToBeCleared = nextDoc;
}
// cleanup, we recycle what we opened, but not the parameters
// nextDoc and docToBeCleared are null already;
v.recycle();
} catch(Exception e) {
e.printStackTrace();
}
}
让我们知道你的进步。