D.Bugger
D.Bugger

Reputation: 2359

XPages: why is my application bean instantiated twice?

XPages moves in mysterious ways again. It displays behaviour I can only explain by assuming that an application-scope managed bean is created twice. The managed bean contains a Map for saving session-dependent data, actually based on SessionID. I ask the bean for the session data using the same SessionID, and I get different results. The console displays new SystemData twice...

This is part of what I have in my faces-config.xml file:

<managed-bean>
<managed-bean-name>SystemData</managed-bean-name>
<managed-bean-class>nl.domain.SystemData</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>

The class SystemData starts with:

public class SystemData implements Serializable {
    private static Map<String, WebLog> webLogs = new HashMap<String, WebLog>();

    private static final long serialVersionUID = -1L;
    public SystemData() throws NotesException {
        System.out.print("new SystemData");
        init();
    }

    public static WebLog getWebLog() throws NotesException {
        if (!isWebLogActive())
            return null;
        BaseXPage baseXPage = new BaseXPage();
        Cookie sessionCookie = (Cookie) baseXPage.getCookie().get("SessionID");
        if (sessionCookie == null)
            return null;
        String sessionId = sessionCookie.getValue();
        if (!webLogs.containsKey(sessionId))
            webLogs.put(sessionId, new WebLog(sessionId));
        return webLogs.get(sessionId);
    }

    ...

And the WebLog class:

public class WebLog implements Serializable {
    private String id = null;
    private Map<String, Object> logMap = null;
    private Date started = null;

    public WebLog(String id) throws NotesException {
//      System.out.print("new WebLog");
        started = new Date();
        this.id = id;
    }

    public void open() {
        if (logMap == null) {
            logMap = new HashMap<String, Object>();
            logMap.put("Form", "BWLog");
            logMap.put("SessionStarted", started);
            logMap.put("SessionID", id);
        }
    }
    ...

What I see in the logs that are produced is this:

View with log documents

Logs are categorized by SessionStarted, the 1st and 3rd page have the same start date/time, yet the 2nd differs.

Other info:

I'm completely baffled... Any hints to solve this problem would be more than welcome!!

Thank you all!

Upvotes: 0

Views: 110

Answers (1)

D.Bugger
D.Bugger

Reputation: 2359

Despite all efforts in cleaning up the code, nothing really helped. So I started thinking why always the 2nd page triggered the instantiation (if it was that) of a new managed bean.

In fact, there are many redirections for the website in their address book. Most of them, e.g. for the home page, point to SITE.nsf, yet there are some that use Site.nsf. Apparently the (Linux-based) Domino server sees this as 2 different links, it handles them the same (everything works), yet internally it creates 2 different managed beans (application scope).

This is for Domino R9.0.1FP7.

Upvotes: 2

Related Questions