4

I have a list of custom objects whose class "implements Comparable".

In my visualforce page I have {!thelist.sort} as an action for a command link.

I get an error:

action="#{thelist.sort}": Unknown method 'List.sort()'

Sort does work on this object, and if I code a method for the controller like this:

public void sortthelist() {
    thelist.sort();
}

And then call put that in the action then it works.

But this is duff code. I don't want to write a method for every instance of a sortable object. The methods of the object should be exposed in the template itself. This is already the case; I can call List.size() in a visualforce page.

Is there something I'm missing or is this a bug/feature?

1
  • 2
    Bug or feature? They haven't put this under known issues, so it's surely a feature.
    – sfdcfox
    Commented Jun 4, 2014 at 14:35

1 Answer 1

5

This is a limitation of the Visualforce engine; lists and sets get cast into something like VisualforceArray, and maps into some other class. While I don't specifically recall their names, it's important to know that they are a superset of the Apex Code collections that have limited functionality. For example, you can't call isEmpty on a VisualforceArray, you have to instead compare size to 0. These odd discrepancies abound in Visualforce. Maps, as another example, will throw fatal exceptions if you reference a key that doesn't exist instead of returning null.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .