How to check not null and not empty string using tags
logic:present
name: Checks for the existence of a JSP bean, in any scope, with the specified name. If property is also specified, checks for a non-null property value for the specified property.
property: Checks for the existence of a non-null property value, returned by a property getter method on the JSP bean (in any scope) that is specified by the name attribute.
logic:notEmpty
Evaluate the nested body content of this tag if the requested variable is neither null, nor an empty string, nor an empty java.util.Collection (tested by the .isEmpty() method on the java.util.Collection interface).
name: The variable to be compared is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.
property: The variable to be compared is the property (of the bean specified by the name attribute) specified by this attribute
Before checking for a property against equal to or not equal to a particular value it is a good practice to ensure it is present and not empty.
<logic:present name="ABCForm" property="abcStatus">
<logic:notEmpty name="ABCForm" property="abcStatus">
<logic:notEqual name="ABCForm" property="abcStatus" value="2">
name: Checks for the existence of a JSP bean, in any scope, with the specified name. If property is also specified, checks for a non-null property value for the specified property.
property: Checks for the existence of a non-null property value, returned by a property getter method on the JSP bean (in any scope) that is specified by the name attribute.
logic:notEmpty
Evaluate the nested body content of this tag if the requested variable is neither null, nor an empty string, nor an empty java.util.Collection (tested by the .isEmpty() method on the java.util.Collection interface).
name: The variable to be compared is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.
property: The variable to be compared is the property (of the bean specified by the name attribute) specified by this attribute
Before checking for a property against equal to or not equal to a particular value it is a good practice to ensure it is present and not empty.
<logic:present name="ABCForm" property="abcStatus">
<logic:notEmpty name="ABCForm" property="abcStatus">
<logic:notEqual name="ABCForm" property="abcStatus" value="2">
1 Comments:
Very useful, thank you much, still after exactly 4 years :D !
Tommaso
Post a Comment
<< Home