How to set up a managed bean to work with Notes document

前端 未结 2 890
故里飘歌
故里飘歌 2020-12-10 18:12

I would like to set up a managed bean that manages a Notes document in Notes view where I store application preferences in (e.g. path on server to store attachments, applic

2条回答
  •  失恋的感觉
    2020-12-10 18:38

    Here is a simple example for such a managed bean.

    First create a Java class. I called it "Config". It reads the first document in view "Config" and puts at instantiation time (=first call) the items in java fields. Doing this you can recycle the domino objects after reading all items and have the values in memory then.

    package de.leonso;
    import java.io.Serializable;
    import lotus.domino.Database;
    import lotus.domino.Document;
    import lotus.domino.View;
    import com.ibm.xsp.extlib.util.ExtLibUtil;
    
    public class Config implements Serializable {
        private static final long serialVersionUID = 1L;    
        private String applicationTitle;
        // ... other private fields
    
        public Config() throws NotesException {
            Database db = ExtLibUtil.getCurrentSession().getCurrentDatabase();
            View view = db.getView("Config");
            Document doc = view.getFirstDocument();
            applicationTitle = doc.getItemValueString("ApplicationTitle");
            // ... read all other items and store them in private fields
            doc.recycle();
            view.recycle();
            db.recycle();
        }
    
        public String getApplicationTitle() {
            return applicationTitle;
        }
    
        // ... getters for other private fields
    
    }
    

    Next define this Java class as a managed bean in faces-config.xml file:

    
      
        config
        de.leonso.Config
        application
      
    
    

    You can use as scope "application" (instance per server) or "session" (instance per user).

    Then you can use the config bean in JavaScript:

    #{javascript:var titel = config.applicationTitle; ...}
    

    or Expression Language:

    #{config.applicationTitle}
    

    That should give you a good starting point to develop an advanced version of a config bean.

提交回复
热议问题