0

i have a util el method that gets an object in a list with index

public static Object get(List list, Integer index) {
        return list.get(index);
    }

and i am calling this method in the xhtml page to get the name of first element in list as follows:

<span>#{[utils:get(myBean.myList,1)].name}</span>

but above expression gives me the following exception:

org.apache.el.parser.ParseException: Encountered " "[" "[ "" at line 1, column 3.
Was expecting one of:
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <STRING_LITERAL> ...
    "true" ...
    "false" ...
    "null" ...
    "(" ...
    "!" ...
    "not" ...
    "empty" ...
    "-" ...
    <IDENTIFIER> ...

any ideas why ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sameh Farahat
  • 1,703
  • 8
  • 22
  • 26

1 Answers1

3

That's because it's invalid syntax. Valid EL syntax is described in the EL specification document. The brace notation [] is used to get an list or array item by index and to dynamically resolve keys of a map. The following is valid syntax in your case:

<span>#{utils:get(myBean.myList,1).name}</span>

However, the custom function is unnecessary. Just use the following syntax:

<span>#{myBean.myList[1].name}</span>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • how to iterate on that list in JS, please see my other question here: http://stackoverflow.com/questions/8644116/iterate-on-list-in-a-backing-bean-with-javascript – Sameh Farahat Dec 27 '11 at 11:44