jsfelstatic-methods

Use static methods in EL


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 ?


Solution

  • 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)}