Remove ${var} in org.apache.commons.lang templates for blank values

143 views Asked by At

I am a new user of org.apache.commons library. I am using this for few templates in my project. For one of the requirment , we are getting inputs from HTML form and rendering as per commons template. I have created a sample template like this -

Hello ${user} how are you doing. Here is your order ${order}

Its working fine when I input both the values from form (user and order). It gives me following output Hello Jhon, here is your order - Two New Books.

But, if I enter only one value, it shows the template variable. like

Hello Jhon, here is your order ${order}

I need to avoid this variable. Any suggestion ?

Note: I can not control form inputs at HTML end, that is a third party form.

Thanks !!

1

There are 1 answers

0
Hitesh On BEST ANSWER

I figures this out.I should set a default value for unresolved variables. I did like

Hello ${user:-} Here is your order ${order:-} 

You can also give default values to unresolved variables like

Hello ${user:-Guest} Here is your order ${order:-air}

Thanks !