克努特赫爾曼在他的評論中已經提到他的[例子] [1]。
如果您希望能夠通過添加按鈕將新配置添加到您的bean中,或者您只是爲了方便地爲所有配置屬性編寫getter和setter,則可以實現DataObject並遍歷所有documentItem以他們寫信給你的bean:
public class ConfigBean implements DataObject {
private static HashMap<Object,Object> config = null;
public ConfigBean() throws NotesException, IOException, ClassNotFoundException{
config = new java.util.HashMap<Object,Object>();
readFromDocument();
}
public void readFromDocument() throws NotesException, IOException, ClassNotFoundException{
Database db = ExtLibUtil.getCurrentSession().getCurrentDatabase();
View view = db.getView("Config");
Document doc = view.getFirstDocument();
//read all Items from document
Iterator<Item> items = doc.getItems().iterator();
while(items.hasNext()){
Item item = items.next();
setValue(item.getName(), item.getValueCustomData());
}
doc.recycle();
view.recycle();
db.recycle();
}
public void saveToDocument(){
//.. write the HashMap back to your document.
}
public Class<ConfigBean> getType(Object id) {
return ConfigBean.class;
}
public Object getValue(final Object key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null.");
}
return config.get(key);
}
public boolean isReadOnly(Object arg0) {
return false;
}
public void setValue(final Object key, final Object value) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null.");
}
config.put(key.toString(), value);
}
}
抱歉無法張貼代碼...
要保存你的bean回您的文檔,你將不得不添加一個方法至極通過HashMap中循環,並寫入這些值返回到您的文檔。您可以在xpage的配置表單中的保存按鈕中調用此方法。
爲了操縱經由的XPage你只需調用ConfigBean.key =「價值」的豆的值,ConfigBean.setValue(「鍵」,「值」),或只是將它們綁定到一個輸入字段:
[1]:How to set up a managed bean to work with Notes document
在這裏,你可以找到使用配置文件從一個bean http://stackoverflow.com/a/17011684/2065611 –
可能重複的例子[如何建立一個管理豆與Notes文檔](http://stackoverflow.com/questions/17010788/how-to-set-up-a-managed-bean-to-work-with-notes-document) – Howli
謝謝!如何回覆Notes文檔通過提交按鈕? – Malin