You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Sarath <be...@yahoo.com> on 2003/12/10 22:24:14 UTC

null value in template

I have a simple user object that has user ID and user
Geo as properties. All I want to check for is the user
object's exsitence in the HttpSession and then print a
welcome message.

something like:
---------------
#if($user!="NULL")
    Welcome $user.userID, $user.geo</font>
#end

I tried "Null", Null, null as the RHS value, but the
if condition wouldnt evaluate. Could some one give me
a solution? 

thanks in advance...
Sarath

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: null value in template

Posted by "J. B. Rainsberger" <jb...@rogers.com>.
Sarath wrote:

> I have a simple user object that has user ID and user
> Geo as properties. All I want to check for is the user
> object's exsitence in the HttpSession and then print a
> welcome message.
> 
> something like:
> ---------------
> #if($user!="NULL")
>     Welcome $user.userID, $user.geo</font>
> #end

Is your session in the VelocityContext? If so, then #if($user) ... #end 
is all you need.
-- 
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: null value in template

Posted by Sarath Babu <be...@yahoo.com>.
Thanks for your quick response Barbara & Rainsberger,

I am sorry I forgot to mention in my earlier mail that
I was using velocity as a view layer on Struts f/w.
Hence, I do not use the velocity context at all.

However, your first answer 'if($!user)' really worked!
Thanks a lot, guys!

regards,
Sarath





--- Barbara Baughman <ba...@utdallas.edu>
wrote:
> Actually, this will not work if you have placed a
> $user object in the
> context, but it's null.  What I usually do is have a
> statement in the
> servlet like:
> if (user!=null) ctx.put("user", user);
> 
> Then the statement below works.  In fact, it's handy
> to handle
> possible null values this way for all references
> that might be null.
> 
> Barbara Baughman
> X2157
> 
> On Wed, 10 Dec 2003, Barbara Baughman wrote:
> 
> > Try
> > #if ($user)
> >
> > Barbara Baughman
> > X2157
> >
> > On Wed, 10 Dec 2003, Sarath wrote:
> >
> > > I have a simple user object that has user ID and
> user
> > > Geo as properties. All I want to check for is
> the user
> > > object's exsitence in the HttpSession and then
> print a
> > > welcome message.
> > >
> > > something like:
> > > ---------------
> > > #if($user!="NULL")
> > >     Welcome $user.userID, $user.geo</font>
> > > #end
> > >
> > > I tried "Null", Null, null as the RHS value, but
> the
> > > if condition wouldnt evaluate. Could some one
> give me
> > > a solution?
> > >
> > > thanks in advance...
> > > Sarath
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > New Yahoo! Photos - easier uploading and
> sharing.
> > > http://photos.yahoo.com/
> > >
> > >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> velocity-user-help@jakarta.apache.org
> > >
> > >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> velocity-user-help@jakarta.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> velocity-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: null value in template

Posted by Barbara Baughman <ba...@utdallas.edu>.
Actually, this will not work if you have placed a $user object in the
context, but it's null.  What I usually do is have a statement in the
servlet like:
if (user!=null) ctx.put("user", user);

Then the statement below works.  In fact, it's handy to handle
possible null values this way for all references that might be null.

Barbara Baughman
X2157

On Wed, 10 Dec 2003, Barbara Baughman wrote:

> Try
> #if ($user)
>
> Barbara Baughman
> X2157
>
> On Wed, 10 Dec 2003, Sarath wrote:
>
> > I have a simple user object that has user ID and user
> > Geo as properties. All I want to check for is the user
> > object's exsitence in the HttpSession and then print a
> > welcome message.
> >
> > something like:
> > ---------------
> > #if($user!="NULL")
> >     Welcome $user.userID, $user.geo</font>
> > #end
> >
> > I tried "Null", Null, null as the RHS value, but the
> > if condition wouldnt evaluate. Could some one give me
> > a solution?
> >
> > thanks in advance...
> > Sarath
> >
> > __________________________________
> > Do you Yahoo!?
> > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: null value in template

Posted by Barbara Baughman <ba...@utdallas.edu>.
Try
#if ($user)

Barbara Baughman
X2157

On Wed, 10 Dec 2003, Sarath wrote:

> I have a simple user object that has user ID and user
> Geo as properties. All I want to check for is the user
> object's exsitence in the HttpSession and then print a
> welcome message.
>
> something like:
> ---------------
> #if($user!="NULL")
>     Welcome $user.userID, $user.geo</font>
> #end
>
> I tried "Null", Null, null as the RHS value, but the
> if condition wouldnt evaluate. Could some one give me
> a solution?
>
> thanks in advance...
> Sarath
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org