<p>I have a Struts + Velocity structure like for example, a Person class, whose one property is a Car object (with its own getter/setter methods) and it is mapped to a Velocity form that submits to an Action, using ModelDriven and getModel structure.</p>

<p>I what to put a button on the form that shows "View Car" if car property is not null or car.id != 0 or show another button "Choose Car" if car is null or car.id = 0.</p>

<p>How do I code this. I tried something like that in the template file:</p>

<pre><code>#if($car != null)
  #ssubmit("name=view" "value=View Car")
#else
  #ssubmit("name=new" "value=Choose Car")
#end
</code></pre>

<p>But I keep getting error about Null value in the <em>#if</em> line. </p>

<p>I also created a boolean method hasCar() in Person to try, but I can't access it and I don't know why.</p>

<p>And Velocity + Struts tutorials are difficult to find or have good information.</p>

<p>Thanks</p>

[{'answer_id': 24510, 'author': 'Brian Matthews', 'author_id': 1969, 'author_profile': 'https://Stackoverflow.com/users/1969', 'pm_score': 4, 'selected': True, 'text': '<p>You should change the #if line to:</p>\n\n<pre><code>#if($car)\n</code></pre>\n'}, {'answer_id': 64065, 'author': 'Nathan Bubna', 'author_id': 8131, 'author_profile': 'https://Stackoverflow.com/users/8131', 'pm_score': 2, 'selected': False, 'text': "<p>In the upcoming Velocity 1.6 release, you will be able to do <code>#if( $car == $null )</code> without error messages.  This will allow you to distinguish easily between when <code>$car</code> is null and when it is false.  To do that now requires <code>#if( $car &amp;&amp; $car != false )</code>, which just isn't as friendly.</p>\n"}]
['https://Stackoverflow.com/questions/24495', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2274/']