如何从managedBean获取xhtml jsf页面上的会话信息? [英] How to get session information on xhtml jsf page from managedBean?

查看:77
本文介绍了如何从managedBean获取xhtml jsf页面上的会话信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jsp文件中有以下代码,其中包含 getSession 信息:

I have following piece of code in my jsp file which getSession information:

 <jsp:useBean id="bookBean" class="beans.trade.BookBean" scope="session">
    <% bookBean.setSession( request.getSession() ); %>
 </jsp:useBean>

现在,我正在尝试在页面上使用 jsf ,在我的 managedBean 中,我正在调用 EJB 并获取它们的引用.这是示例:

now I am trying to use jsf on the page and in my managedBean I am making call to EJB and getting their references. Here is the sample:

public void setSession(HttpSession session)
{
    super.setSession(session); 
    InitialContext ic = getInitialContext();
    booksLocalOps = ((BookOpsLocalHome) ic.lookup(BookOpsLocalHome.JNDI_NAME)).create();
    books = booksLocalOps.findBooksByOrg("ORG");
}

现在我的 xhtml 页面为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:icecore="http://www.icefaces.org/icefaces/core"
      xmlns:ice="http://www.icesoft.com/icefaces/component"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:p="http://java.sun.com/jsf/core"
      xmlns:ice-cc="http://www.icesoft.com/icefaces-composite-comps">
<h:head>
    <title>bookTemplate</title>
    <link rel="stylesheet" type="text/css" href="/xmlhttp/css/rime/rime.css"/>
</h:head>

<h:body>
    <ice:form>
        <p align="center">
            <ice:outputText value="Book Template" style="text-align:center;font-size:40px;"></ice:outputText>
        </p>
        <br/>
        <br/>

        <p align="center">
            <ice:panelGrid columns="2">
                <ice:panelGrid>
                    <ice:outputText value="Book Name:" style="text-align:left;font-size:20px;"
                                    id="bookName"></ice:outputText>
                </ice:panelGrid>
                <ice:panelGrid>
                    <ice:inputText id="BookNameInputText" style="width: 195px;"
                                   value="#{bookBean.bookName}"></ice:inputText>
                </ice:panelGrid>
            </ice:panelGrid>
        </p>
        <br/>
        <br/>
    </ice:form>
</h:body>
</html>

所以我的问题是如何获取该页面上的 session 信息?

So my question is how can i get session information on that page?

更新

我正在调试应用程序,当我尝试获取 initialContext 时,我最终遇到 javax.servlet.ServletException:会话不能为空引发异常,不确定如何处理这个.

I am debugging the application and when i try to get initialContext then I end up with javax.servlet.ServletException: Session cannot be null exception thrown, not sure how to deal with this.

推荐答案

查看但是您可以使用Java scriplet来进行会话,这将违反ICEfaces约定.因此,只要您可以通过xhtml文件中的ICEfaces标记访问所有bean数据,就不需要访问任何会话.

But you can get your session with a java scriplet which will be against the ICEfaces conventions. so you don't need to access any session as long as you have access to all your bean data through your ICEfaces tags in the xhtml file.

这篇关于如何从managedBean获取xhtml jsf页面上的会话信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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