簡體   English   中英

如何從ManagedBean獲取xhtml jsf頁面上的會話信息?

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

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

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

現在,我試圖在頁面上使用jsf ,並在我的managedBean調用EJB並獲取它們的引用。 這是示例:

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信息?

更新資料

我正在調試應用程序,當我嘗試獲取initialContext我最終遇到javax.servlet.ServletException: Session cannot be null引發異常,不確定如何處理。

這里為您啟動。

但是,您可以使用Java scriplet來進行會話,這將違反ICEfaces約定。 因此,只要您可以通過xhtml文件中的ICEfaces標記訪問所有bean數據,就不需要訪問任何會話。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM