Patrick Kwinten
Patrick Kwinten

Reputation: 2048

Read / Write to Notes document using managed bean in XPages

I have set up a managed bean with help of the following code.

And have connected inputboxes on an XPage to the managed bean.

Now I want to save values from the inputboxes back to the underlying Notes document.

How should I do this? Should I set up a save method in the managed bean and call it via a button?

Example code would be helpful.

Upvotes: 0

Views: 439

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30970

In addition to the code you used you have to add setters in Java class for all fields you present in inputboxes for change, e.g.

public void setApplicationTitle(String applicationTitle) {
    this.applicationTitle = applicationTitle;
}

and add a method save()

public void save() throws NotesException {
    Database db = ExtLibUtil.getCurrentSession().getCurrentDatabase();
    View view = db.getView("config");
    Document doc = view.getFirstDocument();
    doc.replaceItemValue("ApplicationTitle", applicationTitle);
    // ... replace all other items changed by user
    doc.save(true, true);
    doc.recycle();
    view.recycle();
}

and call this method in a button using SSJS

#{javascript:config.save()}

This is just a starting point for development. In addition, you have to care about possible exceptions. You should also allow changes for admins only as this config document seems to keep general settings for your application.

Upvotes: 3

Related Questions