You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ashish chawre <as...@gmail.com> on 2010/12/10 16:22:27 UTC
Problem using scriplet object in s:if tag
Hi list,
I am trying to use an object from scriplet to <s:if> tag for a conditional
display purpose.
Here is the code:
In jsp I am fetching user record from the session
<%
UserDTO userDTO = (UserDTO)session.getAttribute("user");
%>
Now I like to show Logout label only if userDTO is avail
<s:if test="%{#userDto != null}">Logout</s:if>
It doesn't seem to be working out properly. Can anybody please point the
mistake I am doing.
Thanks in advance!
-- Ashish
Re: Problem using scriplet object in s:if tag
Posted by Li Ying <li...@gmail.com>.
It don't works, because the JSP local variable is not an OGNL local variable.
The JSP local variable will be translated into a local variable of the
Servlet code,
and it is a local variable of Java language, so you can not reference it in
the OGNL expression.
An OGNL local variable should be [put into] the value stack of OGNL context,
before you can reference it in other OGNL expression.
Before you can reference an OGNL local variable, you need define it,
using <s:set> tag (In struts2).
See:
http://www.opensymphony.com/ognl/html/LanguageGuide/basicSyntax.html
and
http://www.opensymphony.com/ognl/html/LanguageGuide/varref.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problem using scriplet object in s:if tag
Posted by ashish chawre <as...@gmail.com>.
Thanks.. attr doesn't seem to be working in this scenario. I will be trying
using <s:set.. to solve my purpose.
-- Ashish
On Fri, Dec 10, 2010 at 8:43 AM, Biesbrock, Kevin <Biesbrock.Kevin@aoins.com
> wrote:
> Oh, I thought you were replacing the scriplets. Why would you want to
> mix them?
>
> I'm not sure how ognl works, whether or not it would have access to a
> page context set outside of ognl.
>
> At any rate, you can try using:
> <s:if test="%{#attr.userDto != null}">Logout</s:if>
>
> the "attr" context map basically searches all available contexts...I
> think that may be your only option.
>
> Or change your scriplets to use <s:set...
>
> Beez
> r 5347
>
> -----Original Message-----
> From: ashish chawre [mailto:ashish.chawre80@gmail.com]
> Sent: Friday, December 10, 2010 11:37 AM
> To: Struts Users Mailing List
> Subject: Re: Problem using scriplet object in s:if tag
>
> Thanks a lot Kevin. It works but I am wondering why is the user userDTO
> not working. If we have a requirement something like this where we have
> to use any variable from scriplet in struts tag then how we will do
> that.
>
> -- Ashish
>
> On Fri, Dec 10, 2010 at 7:30 AM, Biesbrock, Kevin
> <Biesbrock.Kevin@aoins.com
> > wrote:
>
> > try this:
> >
> > <s:if test="%{#session.user != null}">Logout</s:if>
> >
> > It's stored in session and your attribute name is user per your
> > previous scriplet.
> >
> >
> > Beez
> > r 5347
> >
> > -----Original Message-----
> > From: ashish chawre [mailto:ashish.chawre80@gmail.com]
> > Sent: Friday, December 10, 2010 10:22 AM
> > To: Struts Users Mailing List
> > Subject: Problem using scriplet object in s:if tag
> >
> > Hi list,
> >
> > I am trying to use an object from scriplet to <s:if> tag for a
> > conditional display purpose.
> > Here is the code:
> >
> > In jsp I am fetching user record from the session <%
> > UserDTO userDTO = (UserDTO)session.getAttribute("user");
> > %>
> >
> > Now I like to show Logout label only if userDTO is avail <s:if
> > test="%{#userDto != null}">Logout</s:if>
> >
> > It doesn't seem to be working out properly. Can anybody please point
> > the mistake I am doing.
> >
> > Thanks in advance!
> >
> > -- Ashish
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
RE: Problem using scriplet object in s:if tag
Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
Oh, I thought you were replacing the scriplets. Why would you want to
mix them?
I'm not sure how ognl works, whether or not it would have access to a
page context set outside of ognl.
At any rate, you can try using:
<s:if test="%{#attr.userDto != null}">Logout</s:if>
the "attr" context map basically searches all available contexts...I
think that may be your only option.
Or change your scriplets to use <s:set...
Beez
r 5347
-----Original Message-----
From: ashish chawre [mailto:ashish.chawre80@gmail.com]
Sent: Friday, December 10, 2010 11:37 AM
To: Struts Users Mailing List
Subject: Re: Problem using scriplet object in s:if tag
Thanks a lot Kevin. It works but I am wondering why is the user userDTO
not working. If we have a requirement something like this where we have
to use any variable from scriplet in struts tag then how we will do
that.
-- Ashish
On Fri, Dec 10, 2010 at 7:30 AM, Biesbrock, Kevin
<Biesbrock.Kevin@aoins.com
> wrote:
> try this:
>
> <s:if test="%{#session.user != null}">Logout</s:if>
>
> It's stored in session and your attribute name is user per your
> previous scriplet.
>
>
> Beez
> r 5347
>
> -----Original Message-----
> From: ashish chawre [mailto:ashish.chawre80@gmail.com]
> Sent: Friday, December 10, 2010 10:22 AM
> To: Struts Users Mailing List
> Subject: Problem using scriplet object in s:if tag
>
> Hi list,
>
> I am trying to use an object from scriplet to <s:if> tag for a
> conditional display purpose.
> Here is the code:
>
> In jsp I am fetching user record from the session <%
> UserDTO userDTO = (UserDTO)session.getAttribute("user");
> %>
>
> Now I like to show Logout label only if userDTO is avail <s:if
> test="%{#userDto != null}">Logout</s:if>
>
> It doesn't seem to be working out properly. Can anybody please point
> the mistake I am doing.
>
> Thanks in advance!
>
> -- Ashish
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Problem using scriplet object in s:if tag
Posted by ashish chawre <as...@gmail.com>.
Thanks a lot Kevin. It works but I am wondering why is the user userDTO
not working. If we have a requirement something like this where we have to
use any variable from scriplet in struts tag then how
we will do that.
-- Ashish
On Fri, Dec 10, 2010 at 7:30 AM, Biesbrock, Kevin <Biesbrock.Kevin@aoins.com
> wrote:
> try this:
>
> <s:if test="%{#session.user != null}">Logout</s:if>
>
> It's stored in session and your attribute name is user per your previous
> scriplet.
>
>
> Beez
> r 5347
>
> -----Original Message-----
> From: ashish chawre [mailto:ashish.chawre80@gmail.com]
> Sent: Friday, December 10, 2010 10:22 AM
> To: Struts Users Mailing List
> Subject: Problem using scriplet object in s:if tag
>
> Hi list,
>
> I am trying to use an object from scriplet to <s:if> tag for a
> conditional display purpose.
> Here is the code:
>
> In jsp I am fetching user record from the session <%
> UserDTO userDTO = (UserDTO)session.getAttribute("user");
> %>
>
> Now I like to show Logout label only if userDTO is avail <s:if
> test="%{#userDto != null}">Logout</s:if>
>
> It doesn't seem to be working out properly. Can anybody please point the
> mistake I am doing.
>
> Thanks in advance!
>
> -- Ashish
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
RE: Problem using scriplet object in s:if tag
Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
try this:
<s:if test="%{#session.user != null}">Logout</s:if>
It's stored in session and your attribute name is user per your previous
scriplet.
Beez
r 5347
-----Original Message-----
From: ashish chawre [mailto:ashish.chawre80@gmail.com]
Sent: Friday, December 10, 2010 10:22 AM
To: Struts Users Mailing List
Subject: Problem using scriplet object in s:if tag
Hi list,
I am trying to use an object from scriplet to <s:if> tag for a
conditional display purpose.
Here is the code:
In jsp I am fetching user record from the session <%
UserDTO userDTO = (UserDTO)session.getAttribute("user");
%>
Now I like to show Logout label only if userDTO is avail <s:if
test="%{#userDto != null}">Logout</s:if>
It doesn't seem to be working out properly. Can anybody please point the
mistake I am doing.
Thanks in advance!
-- Ashish
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org