diff --git a/pom.xml b/pom.xml
index e4c002a..36fa3f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.github.jpenren
thymeleaf-spring-data-dialect
- 3.3.1
+ 3.4.0-SNAPSHOT
Thymeleaf Spring Data Dialect
Data pagination made easy with Thymeleaf and Spring Data
diff --git a/src/main/java/org/thymeleaf/dialect/springdata/decorator/FullPaginationDecorator.java b/src/main/java/org/thymeleaf/dialect/springdata/decorator/FullPaginationDecorator.java
index 88c017f..15a1ac9 100644
--- a/src/main/java/org/thymeleaf/dialect/springdata/decorator/FullPaginationDecorator.java
+++ b/src/main/java/org/thymeleaf/dialect/springdata/decorator/FullPaginationDecorator.java
@@ -1,19 +1,32 @@
package org.thymeleaf.dialect.springdata.decorator;
-import java.util.Locale;
-
import org.springframework.data.domain.Page;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.dialect.springdata.Keys;
+import org.thymeleaf.dialect.springdata.SpringDataDialect;
import org.thymeleaf.dialect.springdata.util.Messages;
import org.thymeleaf.dialect.springdata.util.PageUtils;
import org.thymeleaf.dialect.springdata.util.Strings;
import org.thymeleaf.model.IProcessableElementTag;
+import java.util.Locale;
+import java.util.Map;
+
public final class FullPaginationDecorator implements PaginationDecorator {
private static final String DEFAULT_CLASS = "pagination";
private static final String BUNDLE_NAME = FullPaginationDecorator.class.getSimpleName();
private static final int DEFAULT_PAGE_SPLIT = 7;
+ private static final String CSS_ATTR_PREFIX = SpringDataDialect.PREFIX + ":" + DEFAULT_CLASS + "-";
+
+ // define custom CSS tags
+ private String cssLaquo = "page-item";
+ private String cssRaquo = "page-item";
+ private String cssPrevious = "page-item";
+ private String cssNext = "page-item";
+ private String cssPageItem = "page-item";
+ private String cssPageLink = "page-link";
+ private String cssDisabled = "disabled";
+ private String cssActive = "active";
public String getIdentifier() {
return "full";
@@ -23,6 +36,8 @@ public String decorate(final IProcessableElementTag tag, final ITemplateContext
Page> page = PageUtils.findPage(context);
+ configureCss(tag.getAttributeMap());
+
// laquo
String firstPage = PageUtils.createPageUrl(context, 0);
Locale locale = context.getLocale();
@@ -93,27 +108,27 @@ private String createPageLinks(final Page> page, final ITemplateContext contex
}
private String getLaquo(Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "laquo", locale);
+ return Messages.getMessage(BUNDLE_NAME, "laquo", locale, cssLaquo, cssPageLink, cssDisabled);
}
private String getLaquo(String firstPage, Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "laquo.link", locale, firstPage);
+ return Messages.getMessage(BUNDLE_NAME, "laquo.link", locale, firstPage, cssLaquo, cssPageLink);
}
private String getRaquo(Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "raquo", locale);
+ return Messages.getMessage(BUNDLE_NAME, "raquo", locale, cssRaquo, cssPageLink, cssDisabled);
}
private String getRaquo(String lastPage, Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "raquo.link", locale, lastPage);
+ return Messages.getMessage(BUNDLE_NAME, "raquo.link", locale, lastPage, cssRaquo, cssPageLink);
}
private String getLink(int pageNumber, Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "link.active", locale, pageNumber);
+ return Messages.getMessage(BUNDLE_NAME, "link.active", locale, pageNumber, cssActive, cssPageLink);
}
private String getLink(int pageNumber, String url, Locale locale) {
- return Messages.getMessage(BUNDLE_NAME, "link", locale, url, pageNumber);
+ return Messages.getMessage(BUNDLE_NAME, "link", locale, url, pageNumber, cssPageItem, cssPageLink);
}
private String getPreviousPageLink(Page> page, final ITemplateContext context) {
@@ -122,7 +137,7 @@ private String getPreviousPageLink(Page> page, final ITemplateContext context)
int previousPage = page.getNumber()-1;
String link = PageUtils.createPageUrl(context, previousPage);
- return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link);
+ return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link, cssPrevious, cssPageLink, cssDisabled);
}
private String getNextPageLink(Page> page, final ITemplateContext context) {
@@ -131,7 +146,42 @@ private String getNextPageLink(Page> page, final ITemplateContext context) {
int nextPage = page.getNumber() + 1;
String link = PageUtils.createPageUrl(context, nextPage);
- return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link);
+ return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link, cssNext, cssPageLink, cssDisabled);
+ }
+
+ private void configureCss(Map attributeMap) {
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "laquo") != null) {
+ this.cssLaquo = attributeMap.get(CSS_ATTR_PREFIX + "laquo");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "raquo") != null) {
+ this.cssRaquo = attributeMap.get(CSS_ATTR_PREFIX + "raquo");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "previous") != null) {
+ this.cssPrevious = attributeMap.get(CSS_ATTR_PREFIX + "previous");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "next") != null) {
+ this.cssNext = attributeMap.get(CSS_ATTR_PREFIX + "next");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "page-item") != null) {
+ this.cssPageItem = attributeMap.get(CSS_ATTR_PREFIX + "page-item");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "page-link") != null) {
+ this.cssPageLink = attributeMap.get(CSS_ATTR_PREFIX + "page-link");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "disabled") != null) {
+ this.cssDisabled = attributeMap.get(CSS_ATTR_PREFIX + "disabled");
+ }
+
+ if (attributeMap.get(CSS_ATTR_PREFIX + "active") != null) {
+ this.cssActive = attributeMap.get(CSS_ATTR_PREFIX + "active");
+ }
}
}
diff --git a/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties b/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties
index 318e8c6..6c51c11 100644
--- a/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties
+++ b/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties
@@ -1,12 +1,12 @@
#pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage
pagination=
-laquo=«
-laquo.link=«
-previous.page=‹
-previous.page.link=‹
-link={1}
-link.active={0}(strom)
-next.page=›
-next.page.link=›
-raquo=»
-raquo.link=»
+laquo=«
+laquo.link=«
+previous.page=‹
+previous.page.link=‹
+link={1}
+link.active={0}(strom)
+next.page=›
+next.page.link=›
+raquo=»
+raquo.link=»