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
  • 671
  • 1
  • 10
  • 16
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,040,783
  • 362
  • 3,548
  • 3,513
jklee
  • 2,078
  • 2
  • 13
  • 23
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
  • 47
  • 6
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
  • 518
  • 4
  • 7