Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking if a bean is null using javascript or other methods

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/or myProp 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>
like image 327
bouncingHippo Avatar asked Oct 02 '22 18:10

bouncingHippo


2 Answers

@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..

like image 131
Vinoth Krishnan Avatar answered Oct 13 '22 12:10

Vinoth Krishnan


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} ??

like image 23
Ash Avatar answered Oct 13 '22 11:10

Ash