If you want to show the key value in black and the text “Key is not present” You have two scenarios.
ps. to achieve this no custom JAVA is needed. So if you do magic in JAVA to get this behavior, please get rid of it. If you use JAVA to obtain the key somewhere, then go ahead (but check if you can use the out of the box integration options!)
You can achieve this with dynamic classes on the text widget.
Widget properties > Appearance > Dynamic classes
Add an expression something like this;
if
$currentObject/Value = empty
then
'text-danger'
else
'text-default'