You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Marc Lustig <ma...@marclustig.com> on 2003/02/17 17:29:03 UTC

Velocity issue

Hi,
I would like to display the value of a field (of a row in the db) if the
field has a value and not display anything if the field has value null.

According to the manual $!var should do the job.
Unfortunately when the field has value null $!var outputs just $!var instead
of nothing.

Can somesome give me a hint what is going on here?
I assume this relates to the way torque maps null-database values to the
object, but I don't know exactly where the problem is located.

Marc


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


AW: Velocity issue

Posted by Marc Lustig <ml...@marclustig.com>.
Thanks Eric for your offer.
See my own answer to my question in the other email that I sent:
---
I had another look into the Velocity manual.
It says $!var works only if $var is not set at all.
It does not work if $var is set to null. In that case the easiest way is:
#set($v="")
#if($var!=null)
#set($v=$var)
#end
---

I find it rather inefficient, that the $!var abbreviation does not work for
null values. Is there any reason behind that?
Problem is most of my fields in the db are set to "null" (the db null) by
default. So I have either to add the above code OR add a convenience method
like getAttributeLabel() for each single $object.Attribute that I want to
output. That's ugly indeed.
Or do you happen to know a more efficient way?



> -----Ursprüngliche Nachricht-----
> Von: Eric Emminger [mailto:eric@ericemminger.com]
> Gesendet: Mittwoch, 19. Februar 2003 20:17
> An: Marc Lustig
> Betreff: Re: Velocity issue
>
>
> Marc
>
> > According to the manual $!var should do the job.
> > Unfortunately when the field has value null $!var outputs just
> $!var instead
> > of nothing.
>
> Yes, that usually works. I think I've seen this happen before.
>
> > Can somesome give me a hint what is going on here?
> > I assume this relates to the way torque maps null-database values to the
> > object, but I don't know exactly where the problem is located.
>
> Is the value in question null when this happens?
>
> Would you send some or all of the Velocity markup in question? You can
> send it to me off-list if it's sensitive.
>
> Eric
>
> --
> Eric Emminger
> eric@ericemminger.com
>


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


Re: Velocity issue

Posted by Eric Emminger <er...@ericemminger.com>.
Marc

> According to the manual $!var should do the job.
> Unfortunately when the field has value null $!var outputs just $!var instead
> of nothing.

Yes, that usually works. I think I've seen this happen before.

> Can somesome give me a hint what is going on here?
> I assume this relates to the way torque maps null-database values to the
> object, but I don't know exactly where the problem is located.

Is the value in question null when this happens?

Would you send some or all of the Velocity markup in question? You can
send it to me off-list if it's sensitive.

Eric

-- 
Eric Emminger
eric@ericemminger.com


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