Hello all,

I am just starting with Tapestry (5.7.1) and use the grid component.
Also, the application module is annotated with @ImportModule(Bootstrap4Module.class), as I want to use Bootstrap 4.x.

However, with this combination the links of the embedded pager component are not drawn in the expected Bootstrap 4 style.


In my opinion, this is because in org.apache.tapestry5.corelib.components.GridPager the render functionality does not distinguish between Bootstrap 3 and 4.

As far as I can see, the pagination component in Bootstrap 4 needs additional CSS classes compared to version 3, namely 'page-item' and 'page-link'.

See:

https://getbootstrap.com/docs/3.4/components/#pagination
https://getbootstrap.com/docs/4.3/components/pagination/

So is the current behaviour a bug, or am I still doing something wrong?

Cheers,
Georg


P.S.: For me, I have solved the problem for the time being with the enclosed patch.

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
index f34e2a1de..8c451e335 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
@@ -24,6 +24,8 @@ import org.apache.tapestry5.http.Link;
 import org.apache.tapestry5.http.services.Request;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.compatibility.Compatibility;
+import org.apache.tapestry5.services.compatibility.Trait;
 
 /**
  * Generates a series of links used to jump to a particular page index within the overall data set.
@@ -78,6 +80,14 @@ public class GridPager
     @Inject
     private Request request;
 
+    @Inject
+    private Compatibility compatibility;
+
+    private boolean isBootstrap4Enabled()
+    {
+        return compatibility.enabled(Trait.BOOTSTRAP_4);
+    }
+
     void beginRender(MarkupWriter writer)
     {
         int availableRows = source.getAvailableRows();
@@ -129,10 +139,13 @@ public class GridPager
 
         if (pageIndex <= lastIndex) return;
 
+        final String bootstrap4pageItem = isBootstrap4Enabled() ? "page-item" : null;
+        final String bootstrap4pageLink = isBootstrap4Enabled() ? "page-link" : null;
+
         if (pageIndex != lastIndex + 1)
         {
-            writer.element("li", "class", "disabled");
-            writer.element("a", "href", "#");
+            writer.element("li", "class", "disabled").attribute("class", bootstrap4pageItem);
+            writer.element("a", "href", "#").attribute("class", bootstrap4pageLink);
             writer.write(" ... ");
             writer.end();
             writer.end();
@@ -142,15 +155,15 @@ public class GridPager
 
         if (pageIndex == currentPage)
         {
-            writer.element("li", "class", "active");
-            writer.element("a", "href", "#");
+            writer.element("li", "class", "active").attribute("class", bootstrap4pageItem);
+            writer.element("a", "href", "#").attribute("class", bootstrap4pageLink);
             writer.write(Integer.toString(pageIndex));
             writer.end();
             writer.end();
             return;
         }
 
-        writer.element("li");
+        writer.element("li").attribute("class", bootstrap4pageItem);
 
         Link link = resources.createEventLink(EventConstants.ACTION, pageIndex);
 
@@ -164,6 +177,8 @@ public class GridPager
                 "data-update-zone", zone,
                 "title", messages.format("core-goto-page", pageIndex));
 
+        element.attribute("class", bootstrap4pageLink);
+
 
         writer.write(Integer.toString(pageIndex));
 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to