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

我怕爱的太早我们不能终老 提交于 2019-12-17 19:46:39

问题


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, application title, which logo to display etc) Has anyone an example for such a bean and how I should use it?

Current I load a SSJS library an place everything in application scope or session scope variables.


回答1:


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:

<faces-config>
  <managed-bean>
    <managed-bean-name>config</managed-bean-name>
    <managed-bean-class>de.leonso.Config</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
  </managed-bean>
</faces-config>

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.




回答2:


The application-scoped bean is definitely a good way to go for this. Once you get more comfortable with Java, you might want to consider using a VariableResolver instead or even an OSGi plugin if some of those options are server-wide. I've also posted an XSnippet for retrieving values from xsp.properties, which may also be appropriate for some settings http://openntf.org/s/retrieve-property-from-xsp.properties-in-nsf-server-or-notes.ini



来源:https://stackoverflow.com/questions/17010788/how-to-set-up-a-managed-bean-to-work-with-notes-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!