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

Share:
10,868
bouncingHippo
Author by

bouncingHippo

where code bounces off me - literally!

Updated on June 04, 2022

Comments

  • bouncingHippo
    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/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>
    
  • Ash
    Ash over 10 years
    that is if your myName is available to the EL.
  • bouncingHippo
    bouncingHippo over 10 years
    i tried your method (i pasted my code for your solution) above. and it still throws the same error..
  • Ash
    Ash over 10 years
    is myName or myProp null ?? does the bean have proper getters/setters ?
  • Ash
    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.