Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xpages

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.

like image 393
Patrick Kwinten Avatar asked Jun 09 '13 14:06

Patrick Kwinten


People also ask

Can @ManagedBean annotation be accessible in the project?

So, it can be accessible in the project. The @ManagedBean annotation in a class automatically registers that class as a resource with the JavaServer Faces. Such a registered managed bean does not need managed-bean configuration entries in the application configuration resource file.

What are the functions of managed bean methods?

Following are the common functions that managed bean methods perform: Performing processing to determine the next page to which the application must navigate It also works as model for JFS Framework.

How to manage managed beans in JSF?

Managed Bean can be accessed from JSF page. In JSF 1.2, a managed bean had to register it in JSF configuration file such as facesconfig.xml. From JSF 2.0 onwards, managed beans can be easily registered using annotations. This approach keeps beans and its registration at one place hence it becomes easier to manage.

What is the default name for a managed bean?

Every managed bean must be registered with the @ManagedBean annotation, we explicitly define a name for the bean, but by default it’s the same name with the first letter in lowercase.


Video Answer


1 Answers

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.

like image 187
Knut Herrmann Avatar answered Sep 28 '22 15:09

Knut Herrmann