Reputation: 665
I'm developing an application based on Spring Framerwork. As a view technology I use integrated with the framework Freemarker. Problems occur when java bean that stores data for vizualization have a null in some fields. There is no null conception in Freemarker so it considers that there is no these fields in the bean at all. I suppose problem could be solved by customization of class that copies data from the java bean to freemarker's hash object referred in template. But i haven't found what class does it in Spring. Is there such class and how is it called?
Upvotes: 3
Views: 852
Reputation: 10262
If any part in your property chain can be null, you can also put parantheses around it to guard against any part being null. E.g. if you pu
${person.car.door.color!"<no value"}
you only guard against the color being null. But if it could also happen that the door, the car or the whole person is gone missing, you have to put
${(person.car.door.color)!"<no value"}
Upvotes: 1
Reputation: 21564
You can use the "!" operator. Here is an example :
${your_property!""}
It will print the empty string "" if your_property
is null.
Upvotes: 1
Reputation: 31903
Usually you just deal with nulls directly in the template. E.g:
${person.surname!"n/a"}
which will print "n/a" in case of a null surname, or just:
${person.surname!}
which will print out the empty string (nothing) in case of a null surname.
Upvotes: 3