Collection of EL functions for data conversion: o:iterableToList() (with alternative o:iterableToModel),
o:setToList(), o:mapToList(), o:joinArray(), o:joinCollection(),
o:joinMap(), o:splitArray(), o:splitList(), and o:toJson().
The o:joinXxx() functions basically joins the elements of the array, collection or map to a string using the given separator.
This may be helpful if you want to display the contents of a collection as a commaseparated string without the need for an <ui:repeat>.
The o:splitXxx() functions basically splits an array or list into an array of subarrays or list of sublists of the given fragment size.
This may be helpful if you want to create a two-dimensional matrix of a fixed width based on a single-dimensional array or list.
The o:toJson() function encodes any object to a string in JSON format according the rules of
Json.encode(Object).
- Author:
- Bauke Scholtz, Arjan Tijms, Radu Creanga <rdcrng@gmail.com>
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringConvert given object to string usingConverter.getAsString(FacesContext, UIComponent, Object)of the converter identified by the given converter ID, invoked withFacesContext.getCurrentInstance(),UIComponent.getCurrentComponent(FacesContext)and given object as arguments.static <E> List<E>iterableToList(Iterable<E> iterable) Converts aIterable<E>to aList<E>.static <E> DataModel<E>iterableToModel(Iterable<E> iterable) Converts anIterable<E>to aDataModel<E>.static StringJoins all elements of the given array to a single string, separated by the given separator.static <E> StringjoinCollection(Collection<E> collection, String separator) Joins all elements of the given collection to a single string, separated by the given separator.static <K,V> String Joins all elements of the given map to a single string, separated by the given key-value pair separator and entry separator.Converts aMap<K, V>to aList<Map.Entry<K, V>>.static StringprintStackTrace(Throwable exception) Print the stack trace of the given exception.static <E> List<E>Converts aSet<E>to aList<E>.static Object[][]splitArray(Object array, int fragmentSize) Splits the given array into an array of subarrays of the given fragment size.Splits the given list into a list of sublists of the given fragment size.static StringEncode given object as JSON.
-
Method Details
-
setToList
Converts aSet<E>to aList<E>.- Type Parameters:
E- The generic set element type.- Parameters:
set- The set to be converted to list of its entries.- Returns:
- The converted list.
-
mapToList
Converts aMap<K, V>to aList<Map.Entry<K, V>>. Each of the entries has the usualgetKey()andgetValue()methods.- Type Parameters:
K- The generic map key type.V- The generic map value type.- Parameters:
map- The map to be converted to list of its entries.- Returns:
- The converted list.
-
iterableToList
Converts aIterable<E>to aList<E>.When iterating specifically over a Set using the above mentioned components
setToList(Set)is an alternative to this.- Type Parameters:
E- The generic iterable element type.- Parameters:
iterable- The Iterable to be converted to a List.- Returns:
- The converted List.
- Since:
- 1.5
-
iterableToModel
Converts anIterable<E>to aDataModel<E>.When iterating specifically over a Set using the above mentioned components
setToList(Set)is an alternative to this. Use this for more general cases or when the exact collection type is unknown.For those same components
iterableToList(Iterable)is another alternative. Use this when a DataModel is specifically needed.- Type Parameters:
E- The generic iterable element type.- Parameters:
iterable- The Iterable to be converted to a DataModel.- Returns:
- The converted DataModel.
- Since:
- 1.5
-
joinArray
Joins all elements of the given array to a single string, separated by the given separator.- Parameters:
array- The array to be joined.separator- The separator to be used. If null, then it defaults to empty string.- Returns:
- All elements of the given array as a single string, separated by the given separator.
- Throws:
IllegalArgumentException- When the given array is not an array at all.- Since:
- 1.3
-
joinCollection
Joins all elements of the given collection to a single string, separated by the given separator.- Type Parameters:
E- The generic collection element type.- Parameters:
collection- The collection to be joined.separator- The separator to be used. If null, then it defaults to empty string.- Returns:
- All elements of the given collection as a single string, separated by the given separator.
- Since:
- 1.3
-
joinMap
Joins all elements of the given map to a single string, separated by the given key-value pair separator and entry separator.- Type Parameters:
K- The generic map key type.V- The generic map value type.- Parameters:
map- The map to be joined.pairSeparator- The key-value pair separator to be used. If null, then it defaults to empty string.entrySeparator- The entry separator to be used. If null, then it defaults to empty string.- Returns:
- All elements of the given map as a single string, separated by the given separators.
- Since:
- 1.3
-
splitArray
Splits the given array into an array of subarrays of the given fragment size. This is useful for creating nested<ui:repeat>structures, for example, when positioning a list of items into a grid based layout system such as Twitter Bootstrap.- Parameters:
array- The array to be split.fragmentSize- The size of each subarray.- Returns:
- A new array consisting of subarrays of the given array.
- Throws:
IllegalArgumentException- When the fragment size is less than 1.- Since:
- 1.6
-
splitList
Splits the given list into a list of sublists of the given fragment size. This is useful for creating nested<ui:repeat>structures, for example, when positioning a list of items into a grid based layout system such as Twitter Bootstrap.- Type Parameters:
E- The generic list element type.- Parameters:
list- The list to be split.fragmentSize- The size of each sublist.- Returns:
- A new list consisting of sublists of the given list.
- Throws:
IllegalArgumentException- When the fragment size is less than 1.- Since:
- 1.6
-
toJson
Encode given object as JSON. Currently, this delegates directly toJson.encode(Object).- Parameters:
object- Object to be encoded as JSON.- Returns:
- The encoded JSON string.
- Since:
- 1.5
- See Also:
-
printStackTrace
Print the stack trace of the given exception.- Parameters:
exception- The exception to print the stack trace for.- Returns:
- The printed stack trace.
-
convert
Convert given object to string usingConverter.getAsString(FacesContext, UIComponent, Object)of the converter identified by the given converter ID, invoked withFacesContext.getCurrentInstance(),UIComponent.getCurrentComponent(FacesContext)and given object as arguments.- Parameters:
converterId- The converter ID of the desired converter instance.object- The object to be converted toStringby the converter identified by given converter ID.- Returns:
- The result of
Converter.getAsString(FacesContext, UIComponent, Object)of the converter identified by the given converter ID, invoked withFacesContext.getCurrentInstance(),UIComponent.getCurrentComponent(FacesContext)and given object as arguments. - Since:
- 3.10
-