Commit 17155e1d authored by michael.simon's avatar michael.simon
Browse files

Update Primefaces to version 10

parent 1245d31a
......@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.SortMeta;
import edu.kit.scc.webreg.entity.BaseEntity;
......@@ -30,6 +31,9 @@ public interface BaseDao<T extends BaseEntity<PK>, PK extends Serializable> {
List<T> findAllPaging(int first, int pageSize, String sortField, GenericSortOrder sortOrder,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
List<T> findAllPaging(int first, int pageSize, Map<String, SortMeta> sortBy,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
Number countAll(Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap);
......
......@@ -33,6 +33,7 @@ import javax.persistence.criteria.Root;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.MatchMode;
import org.primefaces.model.SortMeta;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GenericSortOrder;
......@@ -86,6 +87,40 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
return em.createQuery("select e from " + getEntityClass().getSimpleName() + " e").getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<T> findAllPaging(int first, int pageSize, Map<String, SortMeta> sortBy,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(getEntityClass());
Root<T> root = criteria.from(getEntityClass());
List<Predicate> predicates = predicatesFromFilterMap(builder, root, filterMap);
predicates.addAll(predicatesFromAdditionalFilterMap(builder, root, additionalFilterMap));
criteria.where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
criteria.select(root);
if (attrs != null) {
criteria.distinct(true);
for (String attr : attrs)
root.fetch(attr, JoinType.LEFT);
}
/**
* TODO Sort order here
*/
// if (sortField != null && sortOrder != null && sortOrder != GenericSortOrder.NONE) {
// criteria.orderBy(getSortOrder(builder, root, sortField, sortOrder));
// }
Query q = em.createQuery(criteria);
q.setFirstResult(first).setMaxResults(pageSize);
return q.getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<T> findAllPaging(int first, int pageSize, String sortField,
......@@ -220,22 +255,22 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
}
protected Predicate predicateFromFilterMeta(CriteriaBuilder builder, Root<T> root, String path, FilterMeta filterMeta) {
if (filterMeta.getFilterMatchMode().equals(MatchMode.STARTS_WITH)) {
if (filterMeta.getMatchMode().equals(MatchMode.STARTS_WITH)) {
return builder.like(
builder.lower(this.<String>resolvePath(root, path)),
filterMeta.getFilterValue().toString().toLowerCase() + "%");
}
else if (filterMeta.getFilterMatchMode().equals(MatchMode.ENDS_WITH)) {
else if (filterMeta.getMatchMode().equals(MatchMode.ENDS_WITH)) {
return builder.like(
builder.lower(this.<String>resolvePath(root, path)),
"%" + filterMeta.getFilterValue().toString().toLowerCase());
}
else if (filterMeta.getFilterMatchMode().equals(MatchMode.CONTAINS)) {
else if (filterMeta.getMatchMode().equals(MatchMode.CONTAINS)) {
return builder.like(
builder.lower(this.<String>resolvePath(root, path)),
"%" + filterMeta.getFilterValue().toString().toLowerCase() + "%");
}
else if (filterMeta.getFilterMatchMode().equals(MatchMode.EQUALS)) {
else if (filterMeta.getMatchMode().equals(MatchMode.EQUALS)) {
return builder.like(
builder.lower(this.<String>resolvePath(root, path)),
filterMeta.getFilterValue().toString().toLowerCase());
......
......@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.SortMeta;
import edu.kit.scc.webreg.dao.GenericSortOrder;
import edu.kit.scc.webreg.entity.BaseEntity;
......@@ -35,6 +36,9 @@ public interface BaseService<T extends BaseEntity<PK>, PK extends Serializable>
T findByIdWithAttrs(PK id, String... attrs);
List<T> findAllPaging(int first, int pageSize, Map<String, SortMeta> sortBy,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
List<T> findAllPaging(int first, int pageSize, String sortField,
GenericSortOrder sortOrder, Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs);
......
......@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.SortMeta;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GenericSortOrder;
......@@ -52,6 +53,12 @@ public abstract class BaseServiceImpl<T extends BaseEntity<PK>, PK extends Seria
return getDao().findAll();
}
@Override
public List<T> findAllPaging(int first, int pageSize, Map<String, SortMeta> sortBy,
Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs) {
return getDao().findAllPaging(first, pageSize, sortBy, filterMap, additionalFilterMap, attrs);
}
@Override
public List<T> findAllPaging(int first, int pageSize, String sortField,
GenericSortOrder sortOrder, Map<String, Object> filterMap, Map<String, FilterMeta> additionalFilterMap, String... attrs) {
......
......@@ -17,9 +17,8 @@ import java.util.Map;
import org.primefaces.model.FilterMeta;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SelectableDataModel;
import org.primefaces.model.SortOrder;
import org.primefaces.model.SortMeta;
import edu.kit.scc.webreg.dao.GenericSortOrder;
import edu.kit.scc.webreg.entity.BaseEntity;
import edu.kit.scc.webreg.service.BaseService;
......@@ -56,17 +55,12 @@ public class GenericLazyDataModelImpl<E extends BaseEntity<PK>, T extends BaseSe
}
@Override
public List<E> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, FilterMeta> additionalFilterMap) {
public List<E> load(int first, int pageSize,
Map<String, SortMeta> sortBy, Map<String, FilterMeta> additionalFilterMap) {
List<E> returnList;
if (sortOrder == SortOrder.ASCENDING)
returnList = getService().findAllPaging(first, pageSize, sortField, GenericSortOrder.ASC, filterMap, additionalFilterMap, attrs);
else if (sortOrder == SortOrder.DESCENDING)
returnList = getService().findAllPaging(first, pageSize, sortField, GenericSortOrder.DESC, filterMap, additionalFilterMap, attrs);
else
returnList = getService().findAllPaging(first, pageSize, sortField, GenericSortOrder.NONE, filterMap, additionalFilterMap, attrs);
returnList = getService().findAllPaging(first, pageSize, sortBy, filterMap, additionalFilterMap, attrs);
setPageSize(pageSize);
......@@ -92,7 +86,7 @@ public class GenericLazyDataModelImpl<E extends BaseEntity<PK>, T extends BaseSe
}
@Override
public Object getRowKey(E object) {
return object.getId();
public String getRowKey(E object) {
return object.getId().toString();
}
}
......@@ -82,7 +82,12 @@
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0</version>
<version>10.0.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>10.0.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment