2012-03-14 18 views
1

私はどの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例外で終わります。

+1

[類似の質問はJSFセッション](http://stackoverflow.com/questions/1282251/saving-data-to-session-in-jsf)を参照してください。 – JMelnik

+1

BalusCが提案したように、私は 'FacesContext context = FacesContext.getCurrentInstance(); HTTPセッションをBeanで取得し、セッションに存在するuserDetails情報を取得することができました。 – Rachel

答えて

0

起動時にはhereをご覧ください。

しかし、あなたはICEfacesの慣行に反するJavaのスクリプレットを使ってセッションを得ることができます。 xhtmlファイルのICEfacesタグを使用してすべてのBeanデータにアクセスできる限り、どのセッションにもアクセスする必要はありません。

+2

これが本当にどのように機能するかについてもっと詳しく説明できますが、これについて多くのことを理解することはできません。 – Rachel

関連する問題