checking if a bean is null using javascript or other methods
10,868
Solution 1
@bouncingHippo Use struts logic tag for this null checking purpose. Like,
<logic:present name="<%=myName%>" property="<%=myProp%>">
<bean:define id="myBean" name="<%=myName%>" property="<%=myProp%>"/>
</logic:present>
Let me know if this helps..
Solution 2
EDITED as per additional information provided:
<c:if test="${not empty myName}">
... your bean def
</c:if>
Ignore: or maybe something like this: ${empty myBean} or ${not empty myBean} ??
Comments
-
bouncingHippo almost 2 years
The below code snippets work when the values used to create myBean is not null.
How do I take care of the scenario when
myBean
has null value? Is there a way to check the bean's value?<bean:define id="myBean" name="<%=myName%>" property="<%=myProp%>"/>
now if
myName
and/ormyProp
is null,Error
javax.servlet.jsp.JspException: Define tag cannot set a null value
error.Attempted solution:
<c:if test="${not empty myBean}"> <bean:define id="myBean" name="<%=myName%>" property="<%=myProp%>"/> </c:if>
-
Ash over 10 yearsthat is if your myName is available to the EL.
-
bouncingHippo over 10 yearsi tried your method (i pasted my code for your solution) above. and it still throws the same error..
-
Ash over 10 yearsis myName or myProp null ?? does the bean have proper getters/setters ?
-
Ash over 10 years@bouncingHippo what you are trying to do here is get the value of property myProp from the bean myName and make it available through myBean. Check what is missing in your code.