如何从JBlet Portal 2.5.4中的servlet获取信息到portlet

时间:2009-02-20 12:06:30

标签: java-ee jboss jboss-portal

我有一个基于JBoss Portal 2.5.4构建的门户,需要有一些I18N。在login.jsp页面(在portal-server.war中),我们添加了一个语言切换。页面上的一个链接是忘记密码工具。

出于与外观相关的原因,ForgetPassword页面在我们的JBoss Portal中实现为最大化的portlet。但是,显然,还没有用户对象,因为还没有登录。

那么如何将用户在login.jsp上选择的语言环境信息传递给忘记密码jsp?

我试过了:

  • 会话变量(没有,他们不会越过战争)
  • cookies(JBoss Portal吞下它们)
  • URL参数(JBoss Portal也吞下它们)
  • System.setProperty() - 当他们到达ForgetPassword jsp时,它们被重置。

这些都在Windows Vista或2003上运行。

我是否缺少一些明显的技术?我只需要咬紧牙关并将我的ForgetPassword页面重新组织为servlet,以便获取URL参数吗?

1 个答案:

答案 0 :(得分:0)

好的,我发现了一种机制 - 在portal-object.xml中创建一个新的portlet窗口(ForgotPasswordWindow_de):

<window>
    <window-name>ForgotPasswordWindow_de</window-name>
    <instance-ref>UserMgmtPortletInstance_de</instance-ref>
    <region>center</region>
<height>0</height>
</window>

指向portlet-instances.xml中的新portlet实例(UserMgmtPortletInstance_de),该实例指向相同的Portlet,并定义了lang首选项。

<deployments>
   <deployment>
        <instance>
           <instance-id>UserMgmtPortletInstance</instance-id>
           <portlet-ref>UserMgmtPortlet</portlet-ref>
           <preferences>
            <preference>
                <name>lang</name>
                <value>en</value>
                <read-only>true</read-only>
            </preference>
           </preferences>
          <security-constraint>
              <policy-permission>     
                <unchecked/>                
                 <action-name>view</action-name>
              </policy-permission>
           </security-constraint>
        </instance>
   </deployment>
   <!-- add new deployment for UserMgmtPortletInstance_de -->
   <deployment>
        <instance>
           <instance-id>UserMgmtPortletInstance_de</instance-id>
           <portlet-ref>UserMgmtPortlet</portlet-ref>
           <preferences>
            <preference>
                <name>lang</name>
                <value>de</value>
                <read-only>true</read-only>
            </preference>
           </preferences>
          <security-constraint>
              <policy-permission>     
                <unchecked/>                
                 <action-name>view</action-name>
              </policy-permission>
           </security-constraint>
        </instance>
   </deployment>
</deployments>

然后,在Portlet doView()代码中,我找到了这个首选项,并设置了一个属性。

    String lang = request.getPreferences().getValue("lang", null);

    request.setAttribute("lang", lang);

然后,在jsp中,我查看属性,并设置区域设置。

String locale = (String) request.getAttribute("lang");

为了全力以赴,登录页面有一个开关,如果语言是德语,则调用ForgotPasswordWindow_de而不是ForgotPasswordWindow_en