场景:我想要一种通用方法在 XPage 上的(新)文档数据源中创建读者和作者字段。我现在的方法是将文档从数据源移交给 postSaveDocument 事件中的 bean 方法。该方法还可以设置为保存或不保存文档,具体取决于将调用的事件(例如 querySaveDocument 事件)。 在我的方法中检查和设置的项目是在我的数据源的 postNewDocument 事件中设置的。奇怪的是,该文档没有保存。调用bean方法后删除。我很惊讶...你对这里发生的事情有什么想法吗?
postNewDocument事件代码:
document1.setValue("$rnaAuthors", "Foo")
document1.setValue("Foo", "Bar")
postSaveDocument事件代码:
rna.save(document1.getDocument(true), true)
bean 在我的 faces-config.xml 中配置:
<managed-bean>
<managed-bean-name>rna</managed-bean-name>
<managed-bean-class>com.olb.ReadWriteAccess
</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
这是 bean 代码:
package com.olb;
import java.io.Serializable;
import java.util.Vector;
import lotus.domino.Document;
import lotus.domino.Item;
import lotus.domino.NotesException;
public class ReadWriteAccess implements Serializable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
public void save(Document doc, boolean saveIt) {
try {
// check if special items exist
if (!doc.hasItem("$rnaReaders") && !doc.hasItem("$rnaAuthors"))
return;
// now fetch all the items by name and set the property
Vector v = doc.getItemValue("$rnaReaders");
for (int x = 0; x < v.size(); x++) {
Item it = doc.getFirstItem(v.elementAt(x).toString());
if (it != null) {
if (!it.isReaders())
it.setReaders(true);
}
}
v = doc.getItemValue("$rnaAuthors");
for (int x = 0; x < v.size(); x++) {
Item it = doc.getFirstItem(v.elementAt(x).toString());
if (it != null) {
if (!it.isReaders())
it.setReaders(true);
}
}
if (saveIt) {
doc.save();
}
} catch (NotesException e) {
e.printStackTrace();
try {
if (saveIt) {
doc.replaceItemValue("$rnaError", e.getMessage());
doc.save();
}
} catch (Exception e2) {
}
}
}
}
最佳答案
在您的代码中,您设置的是读者字段而不是作者字段。 XPages 引擎尝试恢复该文档,但无法找到它。这就是为什么在您第二次单击该按钮后会抛出“文档已被删除”错误。
关于java - 通过Java bean修改后文档被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18945941/