Skip to content

Commit

Permalink
add innerElementClass attribute to pagination tag. #928
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshikawaa committed Nov 12, 2019
1 parent 62d27be commit 938bd07
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class PaginationTag extends RequestContextAwareTag {
*/
private String innerElement = PaginationInfo.DEFAULT_INNER_ELM;

/**
* Value of "class" attribute of inner tag of pagination
* @since 5.6.0
*/
private String innerElementClass = PaginationInfo.DEFAULT_INNER_CLASS;

/**
* Display text of the link of back to the top
*/
Expand Down Expand Up @@ -231,6 +237,10 @@ protected void writePageLink(TagWriter tagWriter, PaginationInfo info,
writeAnchor(tagWriter, disabledHref, String.valueOf(page + 1)); // a
}
} else {
if (StringUtils.hasText(innerElementClass)) {
tagWriter.writeAttribute(PaginationInfo.CLASS_ATTR,
innerElementClass);
}
writeAnchor(tagWriter, info.getPageUrl(page), String.valueOf(page
+ 1)); // a
}
Expand Down Expand Up @@ -275,6 +285,10 @@ protected void writeFirstAndPreviousLink(TagWriter tagWriter,
// write first link

tagWriter.startTag(innerElement); // <li>
if (StringUtils.hasText(innerElementClass)) {
tagWriter.writeAttribute(PaginationInfo.CLASS_ATTR,
innerElementClass);
}

writeAnchor(tagWriter, info.getFirstUrl(), firstLinkText); // a

Expand All @@ -285,6 +299,10 @@ protected void writeFirstAndPreviousLink(TagWriter tagWriter,
// write previous link

tagWriter.startTag(innerElement); // <li>
if (StringUtils.hasText(innerElementClass)) {
tagWriter.writeAttribute(PaginationInfo.CLASS_ATTR,
innerElementClass);
}

writeAnchor(tagWriter, info.getPreviousUrl(), previousLinkText); // a

Expand Down Expand Up @@ -330,6 +348,10 @@ protected void writeNextAndLastLink(TagWriter tagWriter,
// write next link

tagWriter.startTag(innerElement); // <li>
if (StringUtils.hasText(innerElementClass)) {
tagWriter.writeAttribute(PaginationInfo.CLASS_ATTR,
innerElementClass);
}

writeAnchor(tagWriter, info.getNextUrl(), nextLinkText); // a

Expand All @@ -340,6 +362,10 @@ protected void writeNextAndLastLink(TagWriter tagWriter,
// write last link

tagWriter.startTag(innerElement); // <li>
if (StringUtils.hasText(innerElementClass)) {
tagWriter.writeAttribute(PaginationInfo.CLASS_ATTR,
innerElementClass);
}

writeAnchor(tagWriter, info.getLastUrl(), lastLinkText); // a

Expand All @@ -366,6 +392,7 @@ public void release() {
this.outerElement = null;
this.outerElementClass = null;
this.innerElement = null;
this.innerElementClass = null;
this.firstLinkText = null;
this.previousLinkText = null;
this.nextLinkText = null;
Expand Down Expand Up @@ -473,6 +500,15 @@ public void setInnerElement(String innerElement) {
this.innerElement = innerElement;
}

/**
* Set value of "class" attribute of inner tag of pagination <br>
* @param innerElementClass Value of "class" attribute of inner tag of pagination
* @since 5.6.0
*/
public void setInnerElementClass(String innerElementClass) {
this.innerElementClass = innerElementClass;
}

/**
* Set display text of the link of back to the top <br>
* @param firstLinkText Display text of the link of back to the top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>Value of "class" attribute of inner tag of pagination</description>
<name>innerElementClass</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>Display text of the link of back to the top</description>
<name>firstLinkText</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ public void testDoStartTagInternal16() throws Exception {
*
* <pre>
* -outer tag class change.
* -inner tag class change.
* </pre>
*/
@Test
Expand All @@ -571,11 +572,43 @@ public void testDoStartTagInternal17() throws Exception {

// customize
tag.setOuterElementClass("all");
tag.setInnerElementClass("item");

int ret = tag.doStartTagInternal();

assertThat(ret, is(TagSupport.EVAL_BODY_INCLUDE));
String expected = "<ul class=\"all\"><li class=\"disabled\"><a href=\"javascript:void(0)\">&lt;&lt;</a></li><li class=\"disabled\"><a href=\"javascript:void(0)\">&lt;</a></li><li class=\"active\"><a href=\"javascript:void(0)\">1</a></li><li><a href=\"?page=1&size=10\">2</a></li><li><a href=\"?page=2&size=10\">3</a></li><li><a href=\"?page=3&size=10\">4</a></li><li><a href=\"?page=4&size=10\">5</a></li><li><a href=\"?page=5&size=10\">6</a></li><li><a href=\"?page=6&size=10\">7</a></li><li><a href=\"?page=7&size=10\">8</a></li><li><a href=\"?page=8&size=10\">9</a></li><li><a href=\"?page=9&size=10\">10</a></li><li><a href=\"?page=1&size=10\">&gt;</a></li><li><a href=\"?page=99&size=10\">&gt;&gt;</a></li></ul>";
String expected = "<ul class=\"all\"><li class=\"disabled\"><a href=\"javascript:void(0)\">&lt;&lt;</a></li><li class=\"disabled\"><a href=\"javascript:void(0)\">&lt;</a></li><li class=\"active\"><a href=\"javascript:void(0)\">1</a></li><li class=\"item\"><a href=\"?page=1&size=10\">2</a></li><li class=\"item\"><a href=\"?page=2&size=10\">3</a></li><li class=\"item\"><a href=\"?page=3&size=10\">4</a></li><li class=\"item\"><a href=\"?page=4&size=10\">5</a></li><li class=\"item\"><a href=\"?page=5&size=10\">6</a></li><li class=\"item\"><a href=\"?page=6&size=10\">7</a></li><li class=\"item\"><a href=\"?page=7&size=10\">8</a></li><li class=\"item\"><a href=\"?page=8&size=10\">9</a></li><li class=\"item\"><a href=\"?page=9&size=10\">10</a></li><li class=\"item\"><a href=\"?page=1&size=10\">&gt;</a></li><li class=\"item\"><a href=\"?page=99&size=10\">&gt;&gt;</a></li></ul>";
assertThat(getOutput(), is(expected));
}

/**
* customized case 7.
*
* <pre>
* -outer tag class change.
* -inner tag class change.
* </pre>
*/
@Test
public void testDoStartTagInternal17_2() throws Exception {

Page<String> page = mock(Page.class);
// set mock behavior
when(page.getNumber()).thenReturn(99);
when(page.getSize()).thenReturn(10);
when(page.getTotalPages()).thenReturn(100);
when(page.getTotalElements()).thenReturn(1000L);

tag.setPage(page);

// customize
tag.setOuterElementClass("all");
tag.setInnerElementClass("item");

int ret = tag.doStartTagInternal();

assertThat(ret, is(TagSupport.EVAL_BODY_INCLUDE));
String expected = "<ul class=\"all\"><li class=\"item\"><a href=\"?page=0&size=10\">&lt;&lt;</a></li><li class=\"item\"><a href=\"?page=98&size=10\">&lt;</a></li><li class=\"item\"><a href=\"?page=90&size=10\">91</a></li><li class=\"item\"><a href=\"?page=91&size=10\">92</a></li><li class=\"item\"><a href=\"?page=92&size=10\">93</a></li><li class=\"item\"><a href=\"?page=93&size=10\">94</a></li><li class=\"item\"><a href=\"?page=94&size=10\">95</a></li><li class=\"item\"><a href=\"?page=95&size=10\">96</a></li><li class=\"item\"><a href=\"?page=96&size=10\">97</a></li><li class=\"item\"><a href=\"?page=97&size=10\">98</a></li><li class=\"item\"><a href=\"?page=98&size=10\">99</a></li><li class=\"active\"><a href=\"javascript:void(0)\">100</a></li><li class=\"disabled\"><a href=\"javascript:void(0)\">&gt;</a></li><li class=\"disabled\"><a href=\"javascript:void(0)\">&gt;&gt;</a></li></ul>";
assertThat(getOutput(), is(expected));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public int getEnd() {
*/
public static final String DEFAULT_INNER_ELM = "li";

/**
* Value of "class" attribute of inner tag of pagination
* @since 5.6.0
*/
public static final String DEFAULT_INNER_CLASS = "";

/**
* Display text of the link of back to the top
*/
Expand Down

0 comments on commit 938bd07

Please sign in to comment.