instanceof into a c:test?

Hello everybody,

I have a big problem,..

I have a JSF data table which can have several types of objects, some have an attribute called name others don't, so I need to have a conditional that depending on the kind of object to show the name (if they have it) or to show a specific string for example: ("Doesn't have"), so I tried this:

<c:choose>

<c:when test="#{null == document.name}">

<h:outputText value="Doesn't have"/>

</c:when>

<c:otherwise>

<h:outputText value="#{document.name}"/>

</c:otherwise>

</c:choose>

But this pulls me a message in console with something like:

javax.faces.el.PropertyNotFoundException: Bean: co.com.company.bo.document.MasiveDocumentBO, property: name

What should I do?

All objects inherits from a class DocumentBO which has all common attributes, inheriting from that class I have:

MasiveDocumentBO

InternDocumentBO

ExternDocumentBO

The first class doesn't have that attribute, what should I do?

Thanks a lot

[1196 byte] By [bogotanoa] at [2007-10-2 23:34:27]
# 1

JSTL and JSF don't really play well together when it comes to conditional stuff like this. It definitely doesn't with the <c:forEach> tag.

The JSF equivalent would be to use the rendered property.

<h:outputText value="Doesn't have" rendered = "#{empty document.name}"/>

<h:outputText value="#{document.name}" rendered="#{not empty document.name}"/>

no JSTL code required.

With regards to the propertyNotFoundException, all the properties that you can potentially access have to be provided. EL doesn't allow for instanceof checks.

My suggestion would be to put getName() on DocumentBO - even if it returns null.

evnafetsa at 2007-7-14 16:16:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...