You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Frank Schaare <Fr...@htp-tel.de> on 2006/04/10 09:19:03 UTC

Acessing SessionInformation as implcit EL Variable

Hallo,

i'm trying to display the session information (like creationTime or 
sessionID) within an JSF EL Variable.

I tried #{sessionScope.creationTime} which is ignored from the renderer. 
Likewise #{facesContext.externalContext.session.creationTime} or 
#{facesContext.currentInstance.externalContext.session.creationTime} 
does not work for me.

I's like to avoid mixing JSF and JSP EL together, is there a chance to 
get the needed Info through JSF EL ?

Re: Acessing SessionInformation as implcit EL Variable

Posted by FSchaare <fs...@htp-tel.de>.
> That being said, it would be pretty easy to create a custom property 
> resolver that solved this 
Nice idea. For the moment, i followed Werner's approach and made a quick 
thingy like #{backingBean.sessionCreated}



Re: Acessing SessionInformation as implcit EL Variable

Posted by Craig McClanahan <cr...@apache.org>.
On 4/10/06, Matthias Wessendorf <mw...@gmail.com> wrote:
>
> >
> > Oops ... my bad.  ExternalContext defines the following method:
> >
> >     public Object getSession(boolean create);
> >
> > recognized by the EL processing.  I was assuming ExternalContext also
> had a
> > getSession() that takes no arguments, like it does for request,
> response,
> > and context.
>
> Since both, Portlet and Servlet environment, provide a getSession()
> method,  which takes no argument (to be clear, in Portlet world it's
> called getPortletSession())
>

That's too bad ... otherwise it would have been possible to use

   #{facesContext.externalContext.request.session}

transparently :-).

Craig

Re: Acessing SessionInformation as implcit EL Variable

Posted by Matthias Wessendorf <mw...@gmail.com>.
>
> Oops ... my bad.  ExternalContext defines the following method:
>
>     public Object getSession(boolean create);
>
> recognized by the EL processing.  I was assuming ExternalContext also had a
> getSession() that takes no arguments, like it does for request, response,
> and context.

Since both, Portlet and Servlet environment, provide a getSession()
method,  which takes no argument (to be clear, in Portlet world it's
called getPortletSession())

Re: Acessing SessionInformation as implcit EL Variable

Posted by Craig McClanahan <cr...@apache.org>.
On 4/10/06, FSchaare <fs...@htp-tel.de> wrote:
>
> Hi folks,
>
> thank you very much for your replies. I tried this one
> #{facesContext.externalContext.session}
> and also this one:
> #{facesContext.externalContext.session.id
>
> which gives me an ugly exception:
> javax.faces.FacesException: Bean:
> org.apache.myfaces.context.servlet.ServletExternalContextImpl, property:
> session


Oops ... my bad.  ExternalContext defines the following method:

    public Object getSession(boolean create);

but this isn't patterned like a JavaBeans property getter, so it will not be
recognized by the EL processing.  I was assuming ExternalContext also had a
getSession() that takes no arguments, like it does for request, response,
and context.

That being said, it would be pretty easy to create a custom property
resolver that solved this ... but it is not possible out of the box.

Craig

Re: Acessing SessionInformation as implcit EL Variable

Posted by Andrew Robinson <an...@gmail.com>.
Try this:

#{facesContext.externalContext.request.session.id}

Which is the same as (in a servlet environment):

FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest req =
(HttpServletRequest)ctx.getExternalContext().getRequest();
String id = req.getSession().getId();

-Andrew

On 4/10/06, FSchaare <fs...@htp-tel.de> wrote:
>
> Hi folks,
>
> thank you very much for your replies. I tried this one
> #{facesContext.externalContext.session}
> and also this one:
> #{facesContext.externalContext.session.id
>
> which gives me an ugly exception:
> javax.faces.FacesException: Bean:
> org.apache.myfaces.context.servlet.ServletExternalContextImpl, property:
> session
>         at
> org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(
> ServletExternalContextImpl.java:421)
>         at
> org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(
> JspViewHandlerImpl.java:234)
>         at
> org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
>         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> ApplicationFilterChain.java:237)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> ApplicationFilterChain.java:157)
>         at
> org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(
> ExtensionsFilter.java:122)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> ApplicationFilterChain.java:186)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> ApplicationFilterChain.java:157)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(
> StandardWrapperValve.java:214)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:104)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
> :520)
>         at
> org.apache.catalina.core.StandardContextValve.invokeInternal(
> StandardContextValve.java:198)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(
> StandardContextValve.java:152)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:104)
>         at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(
> AuthenticatorBase.java:462)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:102)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
> :520)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :137)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:104)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :118)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:102)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
> :520)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(
> StandardEngineValve.java:109)
>         at
> org.apache.catalina.core.StandardValveContext.invokeNext(
> StandardValveContext.java:104)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java
> :520)
>         at org.apache.catalina.core.ContainerBase.invoke(
> ContainerBase.java:929)
>         at org.apache.coyote.tomcat5.CoyoteAdapter.service(
> CoyoteAdapter.java:160)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
>         at
>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection
> (Http11Protocol.java:705)
>         at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(
> ThreadPool.java:683)
>         at java.lang.Thread.run(Unknown Source)
>
>
> I don't know, what these words mean to me, but in fact, there´s no
> method like
> FacesContext.getCurrentInstance
> ().getExternalContext().getSession().getId()
> implemented yet.
>
> I found the method
> FacesContext.getCurrentInstance().getExternalContext().getSession(boolean
> create), but how do i pass the argument ?
>

Re: Acessing SessionInformation as implcit EL Variable

Posted by FSchaare <fs...@htp-tel.de>.
Hi folks,

thank you very much for your replies. I tried this one
#{facesContext.externalContext.session}
and also this one:
#{facesContext.externalContext.session.id

which gives me an ugly exception:
javax.faces.FacesException: Bean: 
org.apache.myfaces.context.servlet.ServletExternalContextImpl, property: 
session
	at 
org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:421)
	at 
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
	at 
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at 
org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at 
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
	at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
	at 
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
	at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
	at java.lang.Thread.run(Unknown Source)


I don't know, what these words mean to me, but in fact, there´s no 
method like 
FacesContext.getCurrentInstance().getExternalContext().getSession().getId() 
implemented yet.

I found the method 
FacesContext.getCurrentInstance().getExternalContext().getSession(boolean 
create), but how do i pass the argument ?

Re: Acessing SessionInformation as implcit EL Variable

Posted by Craig McClanahan <cr...@apache.org>.
On 4/10/06, Andrew Robinson <an...@gmail.com> wrote:
>
> facesContext should exist as a request variable. At least with
> Facelets I know this is true from others mentioning it. I'm not sure
> why it wouldn't be working for you. If you are using facelets, JSP
> variables will not be available (sessionScope for example).
>
> Here is the list of variables that should be available if you are
> rendering using JSP according to Sun:
> http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html


JSF's EL supports a similar set of implicit objects -- they are implemented
inside the default VariableResolver, so they act sort of like managed beans
(in other words you don't have to create them).  The list of supported names
is in the JSF spec (section  5.3.1.2).  Informally, start with the JSP list
referenced above, remove the JSP specific things ("pageContext" and
"pageScope"), and add "facesContext" (the FacesContext instance for the
current request) and "view" (the root component of the current view) that
are JSF specific.  So, things like "sessionScope" *are* available (if you
know the bean is already there) in a JSF expression as well.

Because "facesContext" is supported, you can also get access to the
HttpSession or PortletSession instance with an expression like this:

    #{facesContext.externalContext.session}

One of the nice things about using EL to do this is you don't have to bind
your app to either the Servlet or Portlet APIs directly.  To get the session
id, for example, is just a matter of evaluating:

    #{facesContext.externalContext.session.id}

Craig

Re: Acessing SessionInformation as implcit EL Variable

Posted by Andrew Robinson <an...@gmail.com>.
facesContext should exist as a request variable. At least with
Facelets I know this is true from others mentioning it. I'm not sure
why it wouldn't be working for you. If you are using facelets, JSP
variables will not be available (sessionScope for example).

Here is the list of variables that should be available if you are
rendering using JSP according to Sun:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html

If you are using facelets, I am not sure which are available (I
couldn't find hit for this quickly) (I know that all the JSP variables
are not available).

JSF should not interfere with JSP variables being available or not via
EL unless there is a problem in the EL resolver.

On 4/10/06, Werner Punz <we...@gmx.at> wrote:
> Frank Schaare schrieb:
> > Hallo,
> >
> > i'm trying to display the session information (like creationTime or
> > sessionID) within an JSF EL Variable.
> >
> > I tried #{sessionScope.creationTime} which is ignored from the renderer.
> > Likewise #{facesContext.externalContext.session.creationTime} or
> > #{facesContext.currentInstance.externalContext.session.creationTime}
> > does not work for me.
> >
> > I's like to avoid mixing JSF and JSP EL together, is there a chance to
> > get the needed Info through JSF EL ?
> >
> you have to set a managed bean with properties which deliver the values
> that should do it.
> The facesContent, and sessionScope objects are not managed beans to my
> knowledge.
>
>

Re: Acessing SessionInformation as implcit EL Variable

Posted by Werner Punz <we...@gmx.at>.
Frank Schaare schrieb:
> Hallo,
> 
> i'm trying to display the session information (like creationTime or
> sessionID) within an JSF EL Variable.
> 
> I tried #{sessionScope.creationTime} which is ignored from the renderer.
> Likewise #{facesContext.externalContext.session.creationTime} or
> #{facesContext.currentInstance.externalContext.session.creationTime}
> does not work for me.
> 
> I's like to avoid mixing JSF and JSP EL together, is there a chance to
> get the needed Info through JSF EL ?
> 
you have to set a managed bean with properties which deliver the values
that should do it.
The facesContent, and sessionScope objects are not managed beans to my
knowledge.