繁体   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