46

I am using Struts + Velocity in a Java application, but after I submit a form, the confirmation page (Velocity template) shows the variable names instead an empty label, like the Age in following example:

Name: Fernando

Age: {person.age}

Sex: Male

I would like to know how to hide it!

Community
  • 1
  • 1
Fernando Barrocal
  • 12,584
  • 9
  • 44
  • 51

2 Answers2

78

You can mark variables as "silent" like this:

$!variable

If $variable is null, nothing will be rendered. If it is not null, its value will render as it normally would.

starwarswii
  • 2,187
  • 1
  • 16
  • 19
Jason Sparks
  • 1,306
  • 11
  • 11
14

You will also need to be sure and use the proper syntax. Your example is missing the dollar before the variable. It should be $!{person.age}, not just {person.age}.

Nathan Bubna
  • 6,823
  • 2
  • 35
  • 36