Find your content:

Search form

You are here

Has the ability to reference List's empty method in Visualforce been removed?

 
Share

I wrote some Visualforce code earlier this week that referenced a List's empty method as follows:

<apex:outputText value="No values" rendered="{!myListVar.empty}"/>

It was working all this week and now, after the Winter '13 upgrade, I get an error:

Unknown property 'List.empty'

Error is in expression '{!myListVar.empty}' in component <apex:outputText> in page myPage

I can still reference the empty method of a List in this manner from Visualforce in my DE on na14 (Summer '12), but in the sandbox on cs9 (Winter '13) I get the error.

I can access the size method without any problems:

<apex:outputText value="{!myListVar.size}"/>

However, if I change that exact line of code to:

<apex:outputText value="{!myListVar.empty}"/>

I get the error.

The strange part is that I can save the file just fine without errors. It is a run time exception.

It is not the following:

<!-- Note the *is*. I changed it to this just to test it out --> 
<apex:outputText value="{!myListVar.isEmpty}"/>

which when I save in the Development Mode Visualforce Editor (i.e., bottom of the browser window editor), I get:

Error: Unknown property 'VisualforceArrayList.isempty'

The page was originally API version 24, but I've tried it in 23, 24, 25, and 26 and all do not work on my Winter '13 sandbox.

Has the ability to use the empty method of a List been removed with the Winter '13 release? I didn't see this in the Winter '13 release notes. Is there documentation outside of the release notes on changes to the Visualforce processor/renderer?


Attribution to: Peter Knolle

Possible Suggestion/Solution #1

I just verified that in both API 24.0 and 25.0 it works fine for me.

public List<String> testEmpty {get; set;}

<apex:outputText value="test" rendered="{!(testEmpty.empty)}"/>

Doesn't render "test" on the page, but when I initialize the list in the constructor:

public GenericController()
{
   testEmpty = new List<String>();
}

It renders as expected. On a side note, I do prefer to be explicit with booleans to avoid unexpected null conditions (testEmpty.empty == true).

Although you can easily work around this issue, it's an interesting thing to run into. Assuming you're not talking about custom iterators, which could conceivably introduce naming issues, and barring an actual bug in your org instance, I have no idea what could be happening.


Attribution to: Adam

Possible Suggestion/Solution #2

Lists (and other variables) must be initialized. The testEmpty list with just get/set is actually null, and thus is not empty. It doesn't exist yet. You just made a placeholder for where the list will go. Once you initialize the list in the constructor, the page can access the existing (though empty) list and act appropriately.


Attribution to: DavidSchach
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1269

My Block Status

My Block Content