简体   繁体   English

如何从ManagedBean获取xhtml jsf页面上的会话信息?

[英]How to get session information on xhtml jsf page from managedBean?

I have following piece of code in my jsp file which getSession information: 我的jsp文件中有以下代码,其中包含getSession信息:

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

now I am trying to use jsf on the page and in my managedBean I am making call to EJB and getting their references. 现在,我试图在页面上使用jsf ,并在我的managedBean调用EJB并获取它们的引用。 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");
}

Now I have my xhtml page as: 现在,我的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>

So my question is how can i get session information on that page? 所以我的问题是如何获取该页面上的session信息?

Update 更新资料

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. 我正在调试应用程序,当我尝试获取initialContext我最终遇到javax.servlet.ServletException: Session cannot be null引发异常,不确定如何处理。

Look at here for your startup. 这里为您启动。

But you can get your session with a java scriplet which will be against the ICEfaces conventions. 但是,您可以使用Java scriplet来进行会话,这将违反ICEfaces约定。 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. 因此,只要您可以通过xhtml文件中的ICEfaces标记访问所有bean数据,就不需要访问任何会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM