I am wanting to test for a non-null value using a struts2 tag. This works if I use the following:
<s:if test="myObject.myField != null">..stuff..</s:if>
It also seems to work if I miss out the not-null part, and just do:
<s:if test="myObject.myField">..stuff..</s:if>
However, when myField
is a String
, this no longer works. I prefer the second form as it is more concise, and seems less like putting code in my presentation layer. But I don't want to use it if it's an undocumented feature which is somehow working by accident, as suggested by the fact that it doesn't work for strings.
So my question is, is it ever ok to miss out "!= null"
in the above test?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…