Skip to content

Instantly share code, notes, and snippets.

@mauricecruz
Last active May 17, 2024 03:37
Show Gist options
  • Save mauricecruz/4817190fafde15514578 to your computer and use it in GitHub Desktop.
Save mauricecruz/4817190fafde15514578 to your computer and use it in GitHub Desktop.
Useful Snippets

Get vars and properties of an object

<%-- replace object with var to test --%>
<c:set var="object" value="${product}" />

<c:if test="${!empty object.class.declaredFields}">
    <h2>Object Attributes <em>&dollar;{object.name}</em></h2>
    <ul>
        <c:forEach var="attr" items="${object.class.declaredFields}">
            <c:catch><li><span>${attr.name}</span>${object[attr.name]}</li></c:catch>
        </c:forEach>
    </ul>
</c:if>

<c:if test="${!empty object.class.declaredMethods}">
    <h2>Object Methods<em>&lt;% object.getName() %&gt;</em></h2>
    <ul>
        <c:forEach var="attr" items="${object.class.declaredMethods}">
            <c:catch><li>${attr.name}</li></c:catch>
        </c:forEach>
    </ul>
</c:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment