Checking attribute exists in JSP

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-03-26T10:41:24Z Indexed on 2010/03/26 10:43 UTC
Read the original article Hit count: 574

Filed under:
|
|

Hello,

I have some classes which extends a superclass, and in the JSP I want to show some attributes of these classes. I only want to make one JSP, but I don't know in advance if the object has an attribute or not. So I need a JSTL expression or a tag which checks that the object I pass has this attribute (similar to in operator in javascript, but in the server).

<c:if test="${an expression which checks if myAttribute exists in myObject}">
    <!-- Display this only when myObject has the atttribute "myAttribute" -->
    <!-- Now I can access safely to "myAttribute" -->
    ${myObject.myAttribute}
</C:if>

How can I get this?

Thanks.

© Stack Overflow or respective owner

Related posts about jsp

Related posts about jsp-tags