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 ?
Static methods can be accessed without having to create a new object. A static method can only use and call other static methods or static data members. It is usually used to operate on input arguments (which can always accept), perform calculation and return value.
A static method can be called directly from the class, without having to create an instance of the class. A static method can only access static variables; it cannot access instance variables. Since the static method refers to the class, the syntax to call or refer to a static method is: class name. method name.
A static method in Java is a method that is part of a class rather than an instance of that class. Every instance of a class has access to the method. Static methods have access to class variables (static variables) without using the class's object (instance).
From Wikipedia: Static methods neither require an instance of the class nor can they implicitly access the data (or this, self, Me, etc.) of such an instance. This describes exactly what Objective-C's class methods are not.
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)}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With