4

I have the following EL expression which references a property on the var attribute:

empty _item.addressLine1

addressLine1 is a String property on the Address bean, which is accessed via the personBean.person.addresses property which returns a Set<Address>.

Here is the EL expression in context:

<h:dataTable id="personBeanPersonAddresses" styleClass="data-table" value="#{forgeview:asList(personBean.person.addresses)}" var="_item">
    <h:column>
        <f:facet name="header">
            <h:outputText value="Address Line 1"/>
        </f:facet>
        <h:link outcome="/address/view">
            <f:param name="id" value="#{_item.id}"/>

            <h:panelGroup rendered="#{!empty _item.addressLine1}">
                <h:outputText id="itemAddressLine1" value="#{_item.addressLine1}"/><br/>
            </h:panelGroup>
        </h:link>
    </h:column>
    ....

The problem is the expression always returns false, regardless of whether addressLine1 is the empty string or not. As if to confirm this, The facelet Validator in Eclipse produces the following warning:

This empty expression always evaluates to false. Only string, maps, arrays and collection have meaningful values for the empty operator

But I'm not sure how to fix this. I'm running JBoss AS 7.1 with jboss-el-api_2.2_spec-1.0.0.Final

tekumara
  • 8,357
  • 10
  • 57
  • 69
  • 1
    This warning is invalid. What do you get when you just print `#{_item.addressLine1}`? – BalusC Oct 23 '12 at 12:25
  • #{_item.addressLine1} prints a single space, so it looks like the problem is my data not the empty expression (I'll just ignore the warning as you suggest). Thanks BalusC! – tekumara Oct 23 '12 at 19:53
  • OK, I reposted it as an answer. – BalusC Oct 23 '12 at 19:55

2 Answers2

4

The code looks fine so far. This warning is invalid. Turn off EL validation in Eclipse if it bothers you.

As to the concrete problem, most likely the #{_item.addressLine1} itself is really empty. You need to make sure that this is not empty.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

You can also only ignore this specific warning: Web -> JavaServer Faces Tools -> Validator

  • Constant folding and unused code (section). Empty operator always resolves to false on type (Ignore).
Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85