null in velocity

2004-12-02 Thread THE ULTIMATE SUBBIAH
How to check for null in velocity
for eg. I load a class in the context Class:: car
#if ($car.getFuel() = null ?? )
This does not work.
Thx
_
The happening world of BPO! Know all that you need to know! 
http://www.bpowatchindia.com/msn/ Keep in step with what’s hot!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


XML and velocity

2004-12-02 Thread Subbiah Raman
Hi,
I am trying to use a SAX parser in Velocity context and I need to do the 
following

#set($temp = $root.getRootElement().getChild(email).getText() )
But it throws
org.apache.velocity.exception.ParseErrorException: Encountered email
Any suggestions.
Thx
_
Choose what you want to read. Protect your mail from spam. 
http://server1.msn.co.in/sp04/hotmailspamcontrol/  Win the war in 9 steps!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: null in velocity

2004-12-02 Thread Edgar Poce
The condition is evaluated to determine if it's a boolean (true/false) 
or if it's not null.

#if ($car.fuel)
...
#end
Regards
Edgar
Check http://jakarta.apache.org/velocity/user-guide.html#Conditionals
THE ULTIMATE SUBBIAH wrote:
How to check for null in velocity
for eg. I load a class in the context Class:: car
#if ($car.getFuel() = null ?? )
This does not work.
Thx
_
The happening world of BPO! Know all that you need to know! 
http://www.bpowatchindia.com/msn/ Keep in step with whats hot!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: XML and velocity

2004-12-02 Thread Claude Brisson
On Thu, 2004-12-02 at 12:48, Subbiah Raman wrote:
 Hi,
 I am trying to use a SAX parser in Velocity context and I need to do the 
 following
 
 #set($temp = $root.getRootElement().getChild(email).getText() )
 
 But it throws
 org.apache.velocity.exception.ParseErrorException: Encountered email

There's an unclosed in your statement.
Also, you can simplify the syntax of the getters that take no argument.

Try :

#set($temp = $root.rootElement.getChild(email).text )

Claude



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: null in velocity

2004-12-02 Thread Shinobu Kawai
Hi SUBBIAH,

 How to check for null in velocity
 for eg. I load a class in the context Class:: car
 
 #if ($car.getFuel() = null ?? )

You can use NullTool
  http://wiki.apache.org/jakarta-velocity/NullTool

#if ($null.isNull($car.fuel))

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-02 Thread Mike Kienenberger
Subbiah Raman [EMAIL PROTECTED] wrote:
 I am trying to use a SAX parser in Velocity context and I need to do the 
 following
 
 #set($temp = $root.getRootElement().getChild(email).getText() )
 
 But it throws
 org.apache.velocity.exception.ParseErrorException: Encountered email

In addition to what others have said, you can also use single-quotes inside 
your double-quotes.

#set($temp = $root.getRootElement().getChild('email').getText() )

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: XML and velocity

2004-12-02 Thread Subbiah
Thank you all for your input, it clears some parts of the quetsion.
As you might have quest I have just started using velocity.(a week)

My generic question on VELOCITY is this.
1.  I see velocity very similar to adding sessions in servlets and accessing
them  in the jsp pages. Is this correct ?

2. I am using VELOCITY to generate templates for certain messages that will
be filled at run time. The input is XML and output is any file. We use
velocity because, the client can change the template anytime his fomat
changes, but after using velocity [I might be wrong] I feel he still has to
know the details of the object or java classes to use velocity , for example
I use DOM parser, then the client has to know what methods are there to make
a change in the template.This is like changing the source code of the
generator one thing he need do is rebuild.

Is this the advantage that velocity provides or are that more that my short
sightedness prevenst me from seeing [I am sure there are]

Thank you.

~Subbiah
 -Original Message-
 From: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, December 02, 2004 10:04 AM
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: XML and velocity
 
 Subbiah Raman [EMAIL PROTECTED] wrote:
  I am trying to use a SAX parser in Velocity context and I 
 need to do 
  the following
  
  #set($temp = $root.getRootElement().getChild(email).getText() )
  
  But it throws
  org.apache.velocity.exception.ParseErrorException: 
 Encountered email
 
 In addition to what others have said, you can also use 
 single-quotes inside your double-quotes.
 
 #set($temp = $root.getRootElement().getChild('email').getText() )
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



question about resource loader: class

2004-12-02 Thread yao fei
Hi,
  I've following the instruction using the classload
by putting jarred vm file in the CLASSPATH. And the
loader cannot find it.
ps. I am using linux, and i checked the jar is in the
CLASSPATH. I am running the app in the eclipse. The
error message says it cannot locate the vm.

Can someone tell me what happens?
Thx.



__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: null in velocity

2004-12-02 Thread Terry Steichen
I think you can also do something like this:

#if($car  $car == )

That is, if $car is defined and has no value (ie, null)
  - Original Message - 
  From: Shinobu Kawai 
  To: Velocity Users List 
  Sent: Thursday, December 02, 2004 10:56 AM
  Subject: Re: null in velocity


  Hi SUBBIAH,

   How to check for null in velocity
   for eg. I load a class in the context Class:: car
   
   #if ($car.getFuel() = null ?? )

  You can use NullTool
http://wiki.apache.org/jakarta-velocity/NullTool

  #if ($null.isNull($car.fuel))

  Best regards,
  -- Shinobu Kawai

  -- 
  Shinobu Kawai [EMAIL PROTECTED]

  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]



Re: null in velocity

2004-12-02 Thread Nathan Bubna
I find #if( $!car ==  ) to be the most reliable null test.

On Thu, 2 Dec 2004 14:47:29 -0500, Terry Steichen [EMAIL PROTECTED] wrote:
 I think you can also do something like this:
 
 #if($car  $car == )
 
 That is, if $car is defined and has no value (ie, null)
 
 
   - Original Message -
   From: Shinobu Kawai
   To: Velocity Users List
   Sent: Thursday, December 02, 2004 10:56 AM
   Subject: Re: null in velocity
 
   Hi SUBBIAH,
 
How to check for null in velocity
for eg. I load a class in the context Class:: car
   
#if ($car.getFuel() = null ?? )
 
   You can use NullTool
 http://wiki.apache.org/jakarta-velocity/NullTool
 
   #if ($null.isNull($car.fuel))
 
   Best regards,
   -- Shinobu Kawai
 
   --
   Shinobu Kawai [EMAIL PROTECTED]
 
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: null in velocity

2004-12-02 Thread Barbara Baughman
If you are doing a test for java 'null' value, then
#if ($car.fuel)
will return true if $car.fuel is NOT a java null value.

If you are checking for an empty string, then use the String
comparison.

#if ($car.fuel==)

If you want to check for both:
#if ($!car.fuel==)

I have a general purpose tool with a method that checks for null or
empty or all blanks and include the tool object in all Velocity
contexts.

#if ($tool.isEmpty($car.fuel))

You may have a different requirement that would require a special
method.  Perhaps you want it to return false if fuel is null or empty
or the value 0.  Then you would have to create your own method in the
$car object.

#if ($car.hasFuel())

BTW, always use '==' instead of '=' when making comparisons in
Velocity.

Barbara Baughman
X2157

On Thu, 2 Dec 2004, THE ULTIMATE SUBBIAH wrote:

 How to check for null in velocity
 for eg. I load a class in the context Class:: car

 #if ($car.getFuel() = null ?? )

 This does not work.
 Thx

 _
 The happening world of BPO! Know all that you need to know!
 http://www.bpowatchindia.com/msn/ Keep in step with what’s hot!


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[FAQ] How do you check for null?

2004-12-02 Thread Shinobu Kawai

Hi all,

I thought it's about time the null question go to the FAQ.  I'm trying
to thinking of a way to summarize it.


Problem: I want to check for null, something like this:
#if ($car.fuel == null)


Approach 1: Use the fact that null is evaluated as a false conditional.
  cf. http://jakarta.apache.org/velocity/user-guide.html#Conditionals
#if( ! $car.fuel )

Note : The conditional will also pass if the result of $car.fuel is
the boolean false.  What this approach is actually checking is whether the
reference is null or false.


Approach 2: Use the fact that null is quiet references.
  cf. 
http://jakarta.apache.org/velocity/user-guide.html#Quiet%20Reference%20Notation
#if( $!car.fuel ==  )

Note : The conditional will also pass if the result of $car.fuel is a
blank String.  What this approach is actually checking is whether the reference
is null or blank.
BTW, just checking for blank can be achieved by:
#if( $car.fuel ==  )


Approach 3: Using a Tool.
  cf. http://wiki.apache.org/jakarta-velocity/NullTool
#if( $null.isNull($car.fuel) )

Note : Of course, NullTool must be in the Context as null in this case.


Approach 4: Don't check for null directly, use a self-explaining method.
#if( $car.isFuelEmpty() )

Note : My recommended solution.  You have to implement the method, but
it makes the template so easy-to-read.


Any comments/suggestions to make it more understandable are welcome.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai [EMAIL PROTECTED] 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: question about resource loader: class

2004-12-02 Thread Shinobu Kawai

Hi yao,

   I've following the instruction using the classload
 by putting jarred vm file in the CLASSPATH. And the
 loader cannot find it.
 ps. I am using linux, and i checked the jar is in the
 CLASSPATH. I am running the app in the eclipse. The
 error message says it cannot locate the vm.
 
 Can someone tell me what happens?

We could use a little more detail.
- How have you configured Velocity (the resource loader)?
- How are you calling the template?
- Where is the template in the jar file?

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai [EMAIL PROTECTED] 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XML and velocity

2004-12-02 Thread Shinobu Kawai

Hi Subbiah,

 My generic question on VELOCITY is this.
 1.  I see velocity very similar to adding sessions in servlets and accessing
 them  in the jsp pages. Is this correct ?

In a way, yes.  In Velocity, you put stuff in the Context, and then you
can access them from the template.  In addition to that you have access
to some easy-to-use directives.  :)
http://jakarta.apache.org/velocity/user-guide.html#Directives

 2. I am using VELOCITY to generate templates for certain messages that will
 be filled at run time. The input is XML and output is any file. We use
 velocity because, the client can change the template anytime his fomat
 changes, but after using velocity [I might be wrong] I feel he still has to
 know the details of the object or java classes to use velocity , for example
 I use DOM parser, then the client has to know what methods are there to make
 a change in the template.This is like changing the source code of the
 generator one thing he need do is rebuild.
 
 Is this the advantage that velocity provides or are that more that my short
 sightedness prevenst me from seeing [I am sure there are]

VTL itself is a very simple language.  The problem here is that you
aren't being friendly to the template designers (the client).  If you
put the DOM document itself in the Context, the template designers will
have to know how to use DOM.  But if you extract all the data needed in
java, and put them in the Context in a more user-friendly fashion (like
custom JavaBeans), the only things the template designers need to know
are the reference names of the information plus maybe some custom
methods for doing special things.

Good luck with Velocity!  ;)

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai [EMAIL PROTECTED] 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]