0
votes

I would like to use a Managed Bean to read/write to a single Notes Document. The Notes Document resides in a Notes View and there will be only 1 Notes Document in the View.

How should I setup the Managed Bean? And how should I call this Managed Bean from an XPage design element? I would like to read & write data from the XPage, via the Managed Bean to the Notes Document.

I assume I will present a Form alike UI, with a button to initiate a Submit action.

Can anyone provide a simple example or where can I find such one?

I thank you very much in advance for your assistance!

1
Here you can find an example for using an configuration document from a bean stackoverflow.com/a/17011684/2065611Knut Herrmann
thank you! how do I write back to the Notes Document e.g. via a Submit button?Malin
There's been some shows on NotesIn9 for getting started with managed beans. You might want to check there. I could do a show for this example if needed. Contact me if interested.David Leedy
My code looks so far: title js:&#160;<xp:inputText id="inputText1" value="#{javascript:config.applicationTitle}" /> <xp:br /> title EL:&#160; <xp:text escape="true" id="computedField1" value="#{config.applicationTitle}"/> <xp:br/> <xp:button value="Submit" id="button1"><xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"/></xp:button></xp:view> Things works fine (as long as I have a Notes document in the view ofcourse). I wonder how I can submit changes back to the Notes Document via the Managed Bean probably via a specified save method?Malin

1 Answers

1
votes

as Knut Hermann already mentioned in his commented check out his [example][1].

If you want to be able to add new configs to your bean via a add button or if you are just to convienient to write a getter and setter for all your configuration properties you can implement the DataObject and iterate over all documentItems to write them to your 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); 
    } 

 }

Sorry was not able to post the code...

To save your bean back to your document you will have to add a method wich loops through the HashMap and writes the values back to your document. You can call this method in a save Button in your configuration form on your xpage.

To manipulate the values of the bean via xpage you can just call ConfigBean.key = "value", ConfigBean.setValue("key","value") or just bind them to a input field:

   

  [1]: How to set up a managed bean to work with Notes document