【问题标题】:How to get session information on xhtml jsf page from managedBean?如何从 managedBean 获取有关 xhtml jsf 页面的会话信息?
【发布时间】:2012-03-31 02:49:27
【问题描述】:

我的 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 异常,不知道如何处理这个问题。

【问题讨论】:

  • 按照 BalusC 的建议,我使用了FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(true); 并在我的 Bean 中获取了 HTTP 会话,并且能够获取会话中存在的 userDetails 信息。

标签: java session jsf icefaces


【解决方案1】:

查看here 为您的创业公司。

但是您可以使用违反 ICEfaces 约定的 java scriplet 来获取会话。因此,只要您可以通过 xhtml 文件中的 ICEfaces 标签访问所有 bean 数据,您就不需要访问任何会话。

【讨论】:

  • 您能否详细说明这将如何真正起作用,因为我对此不太了解。
猜你喜欢
  • 2011-11-07
  • 1970-01-01
  • 2014-12-06
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多