1

I have following piece of code in my jsp file which getSession information:

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

now I am trying to use jsf on the page and in my managedBean I am making call to EJB and getting their references. Here is the sample:

public void setSession(HttpSession session)
{
    super.setSession(session); 
    InitialContext ic = getInitialContext();
    booksLocalOps = ((BookOpsLocalHome) ic.lookup(BookOpsLocalHome.JNDI_NAME)).create();
    books = booksLocalOps.findBooksByOrg("ORG");
}

Now I have my xhtml page as:

<!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>

So my question is how can i get session information on that page?

Update

I am debugging the application and when i try to get initialContext then I end up with javax.servlet.ServletException: Session cannot be null exception thrown, not sure how to deal with this.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Rachel
  • 100,387
  • 116
  • 269
  • 365
  • 1
    Try referring [similar question on JSF sessions](http://stackoverflow.com/questions/1282251/saving-data-to-session-in-jsf). – d1e Mar 14 '12 at 21:09
  • 1
    As suggested by BalusC, I used `FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(true);` and got HTTP session in my Bean and was able to get userDetails informations that are present in session. – Rachel Mar 15 '12 at 02:11

1 Answers1

0

Look at here for your startup.

But you can get your session with a java scriplet which will be against the ICEfaces conventions. so you don't need to access any session as long as you have access to all your bean data through your ICEfaces tags in the xhtml file.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
  • 2
    can you elaborate more on how this would really work as am not able to understand much about it. – Rachel Mar 19 '12 at 02:18