会话范围的托管bean在xpages应用程序中似乎不在会话范围内 [英] session-scoped managed bean appears to be not session scoped in an xpages application

查看:96
本文介绍了会话范围的托管bean在xpages应用程序中似乎不在会话范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个会话范围内的托管Bean,以便在domino xpages应用程序中缓存会话用户特定的信息,就像以下代码一样:

I'd wrote a session scoped managed bean to cache the sesion user specific info in a domino xpages application,just like the following codes:

    public class NBUserInfo {
    private String fullUserName;
    private String commonUserName;
    private String displayName;
    private String mailAddress;
    private String themeType;
    private String themeData;

    private Session _session;
    private Database _dbnames;
    private Name _dominoName;

    public NBUserInfo(){
        System.out.println("初始化Managed Bean:NBUserInfo...");
        _session = ExtLibUtil.getCurrentSession();

        try {
            System.out.println(_session.getEffectiveUserName());
            _dbnames = _session.getDatabase(_session.getCurrentDatabase().getServer(), "names.nsf",false);
            _dominoName = _session.createName(_session.getEffectiveUserName());
        } catch (NotesException e) {
            // TODO 自动生成 catch 块
            e.printStackTrace();
        }

    }

    public String getFullUserName() {
        if(fullUserName==null)
            try {
                fullUserName = _dominoName.getCanonical();
            } catch (NotesException e) {
                // TODO 自动生成 catch 块
                e.printStackTrace();
            }
        return fullUserName;
    }

然后,我在faces-config中将其声明为使其成为会话范围的bean:

then, i declared it in the faces-config to make it a session scoped bean:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
  <!--注册受管Beans-->
  <managed-bean>
    <managed-bean-name>NBUser</managed-bean-name>
    <managed-bean-class>com.nbhdtech.common.NBUserInfo</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>
  <!--注册自定义XPAGES根渲染器-->
  <render-kit>
    <renderer>
      <component-family>javax.faces.ViewRoot</component-family>
      <renderer-type>com.ibm.xsp.ViewRootEx</renderer-type>
      <renderer-class>com.nbhdtech.xsp.CustomViewRootRenderer</renderer-class>
    </renderer>
  </render-kit>
  <!--AUTOGEN-START-BUILDER:由 IBM Domino Designer 自动生成。请勿修改。-->
  <!--AUTOGEN-END-BUILDER:自动生成的区段的末尾-->
</faces-config>

在测试Bean时,我通过#{NBUser.fullUserName}使用了它, 它并不总是返回当前domino http会话上下文的用户,例如,我首先由用户"user1"登录并注销,然后由user2登录,似乎没有为新的user2会话重新创建bean,仍然是user1的会话信息.

when testing the bean , I used it through #{NBUser.fullUserName}, it does not always return the user of the current domino http session context,for examples, I get logged in first by user "user1" and logged off,then logged in by user2, the bean seems to not recreated for the new user2 session,just still user1's session info .

有一些解决方法吗?我的多米诺骨牌已配置为LTPAToken SSO配置.非常感谢,如果有任何答案

is there some work around about this? my domino have been configed to LTPAToken SSO config. thanks a lot if any answers about it

推荐答案

正如Mark Leusink所述,XPages中的sessionScope链接到浏览器会话,而不是(登录的)用户会话.

As Mark Leusink mentions, sessionScope in XPages is linked to the browser session and not the (logged in) user session.

因此,您需要一种方法来检查当前用户是否与绑定到您的用户bean的用户匹配.一种方法是在每个请求上在用户bean中调用验证"方法. 验证"方法可能如下所示:

So you need a way to check if the current user matches the user tied to your user bean. One way to do this is to call a "verify" method in your user bean on each request. The "verify" method could look like this:

public void verify() {
    // retrieve the username of the current user
    String currentUser = ExtLibUtil.getCurrentSession().getEffectiveUserName();

    // (re-)init the user bean if another user logged in
    if (!currentUser.equals(getFullUserName())) {
        // Call your constructor logic here
    }
}

您可以在一个中央自定义控件(例如布局的自定义控件)的beforePageLoad事件中调用此验证"方法:

You can call this "verify" method in the beforePageLoadevent of one of your central custom controls (such as a custom control for your layout):

<xp:this.beforePageLoad><![CDATA[#{javascript:
    // (re-)init the userbean if another user logged in
    NBUser.verify();
}]]></xp:this.beforePageLoad>

-

此外,您不应将Domino特定对象存储在Bean中.

Also, you should not store Domino specific objects in a bean.

这篇关于会话范围的托管bean在xpages应用程序中似乎不在会话范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆