I have an Enum
which has certain fields ,which I need to access in my play1.2.4
template
public Enum WORKER{
FARMER,SMITH,GARDENER
}
Suppose I need to check if a 'person' variable in the template is a farmer,smith or gardener ,how can I do it?
#{if person.Type==WORKER.FARMER}
...do something...
#{/if}
Here I get
NullPointerException : Cannot get property 'FARMER' on null object.
So,the template doesn't know about the Enum WORKER.Since a new instance cannot be created for Enum ,how should I make the Enum available to the template?
Use the enum's absolute class name in the template.
E.g. if your enum WORKER
is in the package model.myenums
, the template code would look like this:
#{if person.Type == model.myenums.WORKER.FARMER}
...do something...
#{/if}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With