私はどのgetSession
情報私のJSPファイル内のコードの一部を次のようしている。managedBeanからxhtml jsfページのセッション情報を取得する方法は?
<jsp:useBean id="bookBean" class="beans.trade.BookBean" scope="session">
<% bookBean.setSession(request.getSession()); %>
</jsp:useBean>
今、私はページ上のを使用しようとしていますし、私の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
例外で終わります。
[類似の質問はJSFセッション](http://stackoverflow.com/questions/1282251/saving-data-to-session-in-jsf)を参照してください。 – JMelnik
BalusCが提案したように、私は 'FacesContext context = FacesContext.getCurrentInstance(); HTTPセッションをBeanで取得し、セッションに存在するuserDetails情報を取得することができました。 – Rachel