Search code examples
jspadobecomponentsaemjcr

how to check null from JCR value in Adobe CQ5..?


Hi all i'm new Adobe CQ5, i'm getting values from JCR in Adobe CQ5 component, value is rendering fine but now want to check null, i'm doing like this:

  <% if(<%= properties.get("videoImage") %> != null)
     {
       <img src=<%= properties.get("videoImage") %> />
     }
  %> 

but it generate an error, can any one suggest what i'm doing wrong.


Solution

  • This is better way to achieve it.

    <% pageContext.setAttribute("videoImage", properties.get("videoImage", ""));%>
        <c:if test="${not empty videoImage}">
            <img src="${videoImage}" />
        </c:if>
    

    Ideally set all of your variables to session, request, page context attributes at one place in top and you may use it throughout component jsp, alternatively much cleaner approach will be to declare all of them in a jsp and include them using <cq:include script"path/to/jsp">