What's the Strut's 2 equivalent of the Struts 1 logic:empty tag?
<logic:empty name="foo">
Foo is null or the empty string
</logic:empty>
Thanks.
There is no struts2 tag to do this, there are more possibilities and more expressiveness with OGNL than the struts1 tags, however there does not seem to be a way to check a string for both null and the empty string as succinctly.
The following works:
<s:if test="(myString == null || myString.equals(''))">
myString is blank or null
</s:if>
<s:else>
The value is <s:property value="myString"/>
</s:else>
The test relies on short circuting, so test of null can not be changed with the test for equality.
If the need to test for this comes up often there may be a design issue. With proper validation in place you should not have uninitialized objects for which the view depends but I suppose there are always exceptions.
To add to Quaternion's answer:
You can always add a method in your action for checking particular conditions, eg MyAction.isPropertyXEmpty()
an put it in the <if test=...>
condition
Recall that in Struts2 properties are more type-rich/expressive than in Struts. Don't use Strings if another type is more appropiate. And you can initialize them to non-null values (eg., empty strings) to avoid the null problems.
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