6

I'm facing a strange problem here with EL.

I just wanted to use String.join() in EL but it is not working.

#{String.join(',', myList)}

This is not doing anything in JSF except prevent my page to load. I know i can do this with <ui:repeat> but i need to use it in EL expression.

Any ideas ?

KiriSakow
  • 957
  • 1
  • 12
  • 22
AZVR
  • 65
  • 1
  • 4

3 Answers3

6

You can't call a static method with EL. Create a Bean with a method to call String.join()

@RequestScoped
@Named
public class StringBean {

    public String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) {
        return String.join(delimiter, elements);
    }
}

So you can call #{stringBean.join(',', myList)}

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jklee
  • 2,198
  • 2
  • 15
  • 25
2

i found an approach to this.

register your util class as a bean in the faces-config.xml

<managed-bean>
    <managed-bean-name>String</managed-bean-name>
    <managed-bean-class>java.lang.String</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
</managed-bean>

I am using org.apache.commons.lang3.ArrayUtils and it is working for me.

adrz1
  • 67
  • 7
0

You can write a custom function that exposes your static method as a function in EL. A similar question has been answered here.

Community
  • 1
  • 1
Martín Straus
  • 558
  • 4
  • 7