camel-velocity: empty variable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

camel-velocity: empty variable

Matteo Redaelli
ciao

I use velocity to build a sql statement.

"
update mdl_user set
        idnumber='${in.body.cid}',icq='${in.body.usertype}'
where
        upper(username)=upper('${in.body.userid}')
"

it works fine if ${in.body.cid} and ${in.body.usertype} are not null
if one of them is null (for example ${in.body.cid}), after the execution of the sql statement, the database field idnumber is not null (this is my wish) but contains the string '${in.body.cid}'

what wrong? how could I solve it?


MY route is

                <route>
                        <from uri="activemq:topic:user.update.response" />
                        <to uri="velocity:sql-moodle-user-update.vm" />
                        <to uri="jdbc:moodleDB" />
                </route>

Thanks in advance
Matteo
Reply | Threaded
Open this post in threaded view
|

Re: camel-velocity: empty variable

Claus Ibsen-2
Hi

Its Velocity that just renders it by default if the variable is not there
http://velocity.apache.org/engine/releases/velocity-1.6.2/user-guide.html#variables

You can use ! after the $ then it reneders a space instead
$!{in.body.cid) but if you want it to render null, then you probably
have to do some #if #else #end in VLT templating



On Fri, Apr 3, 2009 at 10:45 AM, Matteo Redaelli
<[hidden email]> wrote:

>
> ciao
>
> I use velocity to build a sql statement.
>
> "
> update mdl_user set
>        idnumber='${in.body.cid}',icq='${in.body.usertype}'
> where
>        upper(username)=upper('${in.body.userid}')
> "
>
> it works fine if ${in.body.cid} and ${in.body.usertype} are not null
> if one of them is null (for example ${in.body.cid}), after the execution of
> the sql statement, the database field idnumber is not null (this is my wish)
> but contains the string '${in.body.cid}'
>
> what wrong? how could I solve it?
>
>
> MY route is
>
>                <route>
>                        <from uri="activemq:topic:user.update.response" />
>                        <to uri="velocity:sql-moodle-user-update.vm" />
>                        <to uri="jdbc:moodleDB" />
>                </route>
>
> Thanks in advance
> Matteo
> --
> View this message in context: http://www.nabble.com/camel-velocity%3A-empty-variable-tp22864380p22864380.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration
Reply | Threaded
Open this post in threaded view
|

Re: camel-velocity: empty variable

Matteo Redaelli
Ok, now it works. Thank you for your help even if it was a issue related to velocity and not camel