Class Sorter.SortData

java.lang.Object
com.flowlogix.jeedao.primefaces.Sorter.SortData
Enclosing interface:
Sorter<TT>

public static class Sorter.SortData extends Object
Manipulates sort criteria requested from the UI and possibly adds or replaces it with application-based sort criteria

Example:

@Named
@ViewScoped
public class SortingDataModel implements Serializable {
    @Inject
    @Getter
    JPALazyDataModel<UserEntity> userModel;

    @PostConstruct
    void initialize() {
        userModel.initialize(builder -> builder.sorter((sortData, cb, root) ->
                // Example: add an ascending zip code-based sort order
                sortData.applicationSort(UserEntity_.zipCode.getName(),
                                var -> cb.asc(root.get(UserEntity_.zipCode)))
                        // Example: if user requests zip code-based sort order,
                        // add address-based sort order to mirror the zip code-based sort order
                        .applicationSort(UserEntity_.zipCode.getName(), UserEntity_.address.getName(), sortData,
                                () -> cb.asc(root.get(UserEntity_.address)),
                                () -> cb.desc(root.get(UserEntity_.address)), () -> null)).build());
    }
}
Author:
lprimak
  • Constructor Details

  • Method Details

    • applicationSort

      public Sorter.SortData applicationSort(String fieldName, Function<Optional<SortMeta>, Order> fp)
      Replaces, or adds application sort criteria to the existing UI sort criteria If the sort criteria is new, it is placed at the lowest sort order
      Parameters:
      fieldName - element to be replaced or added
      fp - lambda to get the application sort criteria
      Returns:
      this fluent API
    • applicationSort

      public Sorter.SortData applicationSort(String fieldName, boolean highPriority, Function<Optional<SortMeta>, Order> fp)
      Replaces, or adds application sort criteria to the existing UI sort criteria If the sort criteria is new, it is placed at either highest or lowest order, depending on the highPriority parameter
      Parameters:
      fieldName - field to be replaced or added
      highPriority - integer (starting with zero, highest priority) where this sort directive is put into the array, only if it's inserted, and not modified
      fp - lambda to get the application sort criteria
      Returns:
      this fluent API
    • applicationSort

      public Sorter.SortData applicationSort(String sourceFieldName, String fieldName, Sorter.SortData sortData, Supplier<Order> ascFn, Supplier<Order> descFn, Supplier<Order> notFoundFn)
      Helper method to apply application sort criteria based on the UI requested sort criteria
      Parameters:
      sourceFieldName - field to retrieve UI requested sort criteria from
      fieldName - field to be replaced or added
      sortData - current sort data
      ascFn - lambda to get ascending sort criteria
      descFn - lambda to get descending sort criteria
      notFoundFn - lambda to get sort criteria when UI did not request sorting
      Returns:
      this fluent API
    • applicationSort

      public Sorter.SortData applicationSort(String sourceFieldName, String fieldName, Sorter.SortData sortData, boolean highPriority, Supplier<Order> ascFn, Supplier<Order> descFn, Supplier<Order> notFoundFn)
      Helper method to apply application sort criteria based on the UI requested sort criteria
      Parameters:
      sourceFieldName - field to retrieve UI requested sort criteria from
      fieldName - field to be replaced or added
      sortData - current sort data
      highPriority - high priority flag, see applicationSort(String, boolean, Function)
      ascFn - lambda to get ascending sort criteria
      descFn - lambda to get descending sort criteria
      notFoundFn - lambda to get sort criteria when UI did not request sorting
      Returns:
      this fluent API