├── .gitignore ├── LICENSE ├── README.md ├── doc ├── aligned-links.png ├── compact.png ├── example.html ├── multiple-tables.png ├── page-size-dropdown.png ├── page-size-select.png ├── pager.png └── simple.png ├── pom.xml └── src └── main ├── java └── org │ └── thymeleaf │ └── dialect │ └── springdata │ ├── Keys.java │ ├── PageObjectAttrProcessor.java │ ├── PageSizeSelectorAttrProcessor.java │ ├── PaginationAttrProcessor.java │ ├── PaginationQualifierAttrProcessor.java │ ├── PaginationSortAscAttrProcessor.java │ ├── PaginationSortAttrProcessor.java │ ├── PaginationSortBaseAttrProcessor.java │ ├── PaginationSortDescAttrProcessor.java │ ├── PaginationSplitAttrProcessor.java │ ├── PaginationSummaryAttrProcessor.java │ ├── PaginationUrlAttrProcessor.java │ ├── SpringDataDialect.java │ ├── decorator │ ├── AbstractPagerDecorator.java │ ├── AlignedLinksDecorator.java │ ├── CompactPagerDecorator.java │ ├── FullPaginationDecorator.java │ ├── PagerDecorator.java │ ├── PaginationDecorator.java │ └── PaginationDecoratorRegistry.java │ ├── exception │ ├── InvalidObjectParameterException.java │ └── PaginationDecoratorNotFoundException.java │ └── util │ ├── Expressions.java │ ├── Messages.java │ ├── PageUtils.java │ └── Strings.java └── resources ├── META-INF └── services │ └── org.thymeleaf.dialect.springdata.decorator.PaginationDecorator └── thymeleaf-spring-data-dialect ├── AlignedLinksDecorator.properties ├── AlignedLinksDecorator_de.properties ├── AlignedLinksDecorator_en.properties ├── AlignedLinksDecorator_es.properties ├── AlignedLinksDecorator_fr.properties ├── AlignedLinksDecorator_gl.properties ├── AlignedLinksDecorator_it.properties ├── AlignedLinksDecorator_nl.properties ├── AlignedLinksDecorator_pt.properties ├── AlignedLinksDecorator_ru.properties ├── AlignedLinksDecorator_zh_CN.properties ├── AlignedLinksDecorator_zh_TW.properties ├── CompactPagerDecorator.properties ├── FullPaginationDecorator.properties ├── FullPaginationDecorator_de.properties ├── FullPaginationDecorator_en.properties ├── FullPaginationDecorator_es.properties ├── FullPaginationDecorator_fr.properties ├── FullPaginationDecorator_gl.properties ├── FullPaginationDecorator_it.properties ├── FullPaginationDecorator_nl.properties ├── FullPaginationDecorator_pt.properties ├── FullPaginationDecorator_ru.properties ├── FullPaginationDecorator_zh_CN.properties ├── FullPaginationDecorator_zh_TW.properties ├── PageSizeSelector.properties ├── PagerDecorator.properties ├── PagerDecorator_de.properties ├── PagerDecorator_en.properties ├── PagerDecorator_es.properties ├── PagerDecorator_fr.properties ├── PagerDecorator_gl.properties ├── PagerDecorator_it.properties ├── PagerDecorator_nl.properties ├── PagerDecorator_pt.properties ├── PagerDecorator_ru.properties ├── PagerDecorator_zh_CN.properties ├── PagerDecorator_zh_TW.properties ├── PaginationSummary.properties ├── PaginationSummary_de.properties ├── PaginationSummary_en.properties ├── PaginationSummary_es.properties ├── PaginationSummary_fr.properties ├── PaginationSummary_gl.properties ├── PaginationSummary_it.properties ├── PaginationSummary_nl.properties ├── PaginationSummary_pt.properties ├── PaginationSummary_ru.properties ├── PaginationSummary_zh_CN.properties └── PaginationSummary_zh_TW.properties /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .settings 3 | .classpath 4 | .project 5 | *.iml 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | /target/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Thymeleaf Spring Data Dialect 2 | Data pagination made easy with thymeleaf and spring data. 3 | 4 | This is a dialect for Thymeleaf that provides some attributes to create pagination and sorting elements, bootstrap style, based on Spring Data. 5 | 6 | Usage 7 | ----- 8 | 9 | Maven dependency: 10 | ```xml 11 | 12 | io.github.jpenren 13 | thymeleaf-spring-data-dialect 14 | 3.6.0 15 | 16 | ``` 17 | 18 | Add the Spring Data dialect to your existing Thymeleaf template engine: 19 | 20 | ```java 21 | templateEngine.addDialect(new SpringDataDialect()); // This line adds the dialect to Thymeleaf 22 | ``` 23 | 24 | If using Spring Boot you can add the following line and the ThymeleafAutoConfiguration class will add the dialect to the template engine. 25 | ```java 26 | @Bean 27 | public SpringDataDialect springDataDialect() { 28 | return new SpringDataDialect(); 29 | } 30 | ``` 31 | 32 | This will introduce the `sd` namespace, and the new attribute processors that 33 | you to use in your pages: `pagination`, `pagination-sort`, `pagination-summary`, 34 | `pagination-url`, `page-object`, `pagination-qualifier` and `page-size-selector`. 35 | 36 | Examples 37 | -------- 38 | In your @Controller 39 | ```java 40 | @RequestMapping("/users") 41 | public String list(ModelMap model, @SortDefault("username") Pageable pageable){ 42 | model.addAttribute("page", userService.find(pageable)); 43 | 44 | return "users/list"; 45 | } 46 | ``` 47 | 48 | Your html page looks like: 49 | ```html 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
UsernameFirst nameLast Name
UsernameNameLast Nameedit
68 | 69 |
70 |
71 |
info
72 |
73 |
74 | 81 |
82 |
83 | ``` 84 | 85 | Use optional attribute sd:pagination-split to configure the number of links to show. 86 | 87 | 88 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/simple.png "Simple") 89 | 90 | Pagination with pager: 91 | ```html 92 | 99 | ``` 100 | 101 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/pager.png "Pager") 102 | 103 | Aligned links: 104 | ```html 105 | 112 | ``` 113 | 114 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/aligned-links.png "Aligned links") 115 | 116 | Compact pager: 117 | ```html 118 |
119 | info 120 |
121 | 122 | 123 | 124 |
125 |
126 | ``` 127 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/compact.png "Compact pager") 128 | 129 | Page size selector (default requires your own javascript code, no action associated): 130 | ```html 131 | Show entries 132 | ``` 133 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/page-size-select.png "Page size selector") 134 | 135 | Page size selector (with javascript code implemented): 136 | ```html 137 | Show entries 138 | ``` 139 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/page-size-select.png "Page size selector") 140 | 141 | Page size selector (dropdown): 142 | ```html 143 |
144 | ``` 145 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/page-size-dropdown.png "Page size selector") 146 | 147 | Multiple tables on the same page: 148 | 149 | On your @Controller 150 | ```java 151 | @RequestMapping("/users") 152 | public String list(ModelMap model, @Qualifier("foo") Pageable first, @Qualifier("bar") Pageable second){ 153 | model.addAttribute("page", userService.find(first)); 154 | model.addAttribute("barPage", userService.find(second)); 155 | 156 | return "users/list"; 157 | } 158 | ``` 159 | ```html 160 |
161 |
162 |
163 |
164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 |
UsernameFirst name
First NameLast Name
178 | 179 | 186 |
187 |
188 |
189 |
190 |
191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 |
UsernameFirst name
First NameLast Name
206 | 207 | 214 |
215 |
216 |
217 |
218 | ``` 219 | 220 | ![alt text](https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/master/doc/multiple-tables.png "Multiple tables") 221 | 222 | By default SpringDataDialect search in the request for the attribute "page" or if one attribute of type org.springframework.data.domain.Page exists. To use another model attribute, use sd:page-object="${attrName}" 223 | 224 | To specify the pagination url use `sd:pagination-url` tag: 225 | ```html 226 | 233 | ``` 234 | 235 | Sort Icons 236 | ---------- 237 | The generated HTML has the CSS classes `sorted`, `sorted-asc` and `sorted-desc`. This allows you to quite easily add some custom CSS to have sort icons in the table headers. 238 | 239 | Example with FontAwesome: 240 | ``` 241 | table.table thead .sorted:after{ 242 | display: inline-block; 243 | font-family: 'FontAwesome'; 244 | opacity: 0.8; 245 | margin-left: 1em; 246 | } 247 | table.table thead .sorted.sorted-desc:after{ 248 | content: "\f15e"; 249 | } 250 | table.table thead .sorted.sorted-asc:after{ 251 | content: "\f15d"; 252 | } 253 | ``` 254 | 255 | Example with Unicode characters: 256 | 257 | ``` 258 | .sorted-desc::after, .sorted-asc::after { 259 | float: right; 260 | } 261 | 262 | .sorted-desc::after{ 263 | content:"\25BC"; 264 | } 265 | 266 | .sorted-asc::after{ 267 | content: "\25B2"; 268 | } 269 | ``` 270 | 271 | -------------------------------------------------------------------------------- /doc/aligned-links.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/aligned-links.png -------------------------------------------------------------------------------- /doc/compact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/compact.png -------------------------------------------------------------------------------- /doc/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
UsernameFirst name
First NameLast Name
23 | 24 |
25 |
26 |
info
27 |
28 |
29 | 36 |
37 |
38 | 39 | 40 | 41 |
42 | 49 | 50 | 57 |
58 | 59 | 60 | 61 |
62 |
63 |
64 |
65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
UsernameFirst name
First NameLast Name
79 | 80 | 87 |
88 |
89 |
90 |
91 |
92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
UsernameFirst name
First NameLast Name
107 | 108 | 115 |
116 |
117 |
118 |
119 | 120 | 121 | 122 |
123 | info 124 |
125 | 126 | 127 | 128 |
129 |
130 | 131 | 132 | 133 | Show entries 134 | 135 | 136 | 137 | Show entries 138 | 139 | 140 | 141 |
142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/multiple-tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/multiple-tables.png -------------------------------------------------------------------------------- /doc/page-size-dropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/page-size-dropdown.png -------------------------------------------------------------------------------- /doc/page-size-select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/page-size-select.png -------------------------------------------------------------------------------- /doc/pager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/pager.png -------------------------------------------------------------------------------- /doc/simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/doc/simple.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | io.github.jpenren 5 | thymeleaf-spring-data-dialect 6 | 3.6.0 7 | 8 | Thymeleaf Spring Data Dialect 9 | Data pagination made easy with Thymeleaf and Spring Data 10 | http://github.com/jpenren/thymeleaf-spring-data-dialect 11 | 2016 12 | 13 | 14 | 15 | Apache License, Version 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | 18 | 19 | 20 | 21 | 22 | Javier Pena 23 | javiprendo@gmail.com 24 | https://github.com/jpenren 25 | 26 | 27 | 28 | 29 | scm:git:git://github.com/jpenren/thymeleaf-spring-data-dialect.git 30 | scm:git:git@github.com:jpenren/thymeleaf-spring-data-dialect.git 31 | git@github.com:jpenren/thymeleaf-spring-data-dialect.git 32 | 33 | 34 | 35 | UTF-8 36 | 17 37 | 17 38 | 17 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-compiler-plugin 46 | 3.8.1 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-source-plugin 51 | 3.2.1 52 | 53 | 54 | attach-sources 55 | 56 | jar 57 | 58 | 59 | 60 | 61 | 62 | org.apache.maven.plugins 63 | maven-javadoc-plugin 64 | 3.3.0 65 | 66 | 67 | attach-javadocs 68 | 69 | jar 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-gpg-plugin 77 | 1.6 78 | 79 | 80 | sign-artifacts 81 | verify 82 | 83 | sign 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.springframework.data 94 | spring-data-commons 95 | 3.0.0 96 | 97 | 98 | org.thymeleaf 99 | thymeleaf 100 | 3.1.1.RELEASE 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/Keys.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | public final class Keys { 4 | 5 | public static final String PAGE_VARIABLE_KEY = "_sd_.page.object"; 6 | public static final String PAGINATION_URL_KEY = "_sd_.pagination.url"; 7 | public static final String PAGINATION_QUALIFIER_PREFIX = "_sd_.pagination.qualifier.prefix"; 8 | public static final String PAGE_EXPRESSION = "${page}"; 9 | public static final String PAGINATION_SPLIT_KEY = "_sd_.pagination.split"; 10 | 11 | private Keys() { 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PageObjectAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.thymeleaf.context.ITemplateContext; 5 | import org.thymeleaf.context.WebEngineContext; 6 | import org.thymeleaf.dialect.springdata.exception.InvalidObjectParameterException; 7 | import org.thymeleaf.dialect.springdata.util.Expressions; 8 | import org.thymeleaf.engine.AttributeName; 9 | import org.thymeleaf.model.IProcessableElementTag; 10 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 11 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 12 | import org.thymeleaf.templatemode.TemplateMode; 13 | 14 | final class PageObjectAttrProcessor extends AbstractAttributeTagProcessor { 15 | private static final String ATTR_NAME = "page-object"; 16 | private static final int PRECEDENCE = 900; 17 | 18 | PageObjectAttrProcessor(final String dialectPrefix) { 19 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 20 | } 21 | 22 | @Override 23 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 24 | String attributeValue, IElementTagStructureHandler structureHandler) { 25 | 26 | if (context instanceof WebEngineContext) { 27 | Object page = Expressions.evaluate(context, attributeValue); 28 | 29 | if (!(page instanceof Page)) { 30 | throw new InvalidObjectParameterException( 31 | "Parameter " + attributeValue + " is not an Page instance!"); 32 | } 33 | 34 | ((WebEngineContext) context).setVariable(Keys.PAGE_VARIABLE_KEY, page); 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PageSizeSelectorAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.data.domain.Page; 10 | import org.thymeleaf.context.ITemplateContext; 11 | import org.thymeleaf.dialect.springdata.util.Messages; 12 | import org.thymeleaf.dialect.springdata.util.PageUtils; 13 | import org.thymeleaf.dialect.springdata.util.Strings; 14 | import org.thymeleaf.engine.AttributeName; 15 | import org.thymeleaf.model.IProcessableElementTag; 16 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 17 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 18 | import org.thymeleaf.templatemode.TemplateMode; 19 | 20 | final class PageSizeSelectorAttrProcessor extends AbstractAttributeTagProcessor { 21 | private static final Logger LOGGER = LoggerFactory.getLogger(PageSizeSelectorAttrProcessor.class); 22 | private static final String MESSAGE_PREFIX = "page.size.selector."; 23 | private static final String DEFAULT_STYLE = MESSAGE_PREFIX + "default"; 24 | private static final String ATTR_NAME = "page-size-selector"; 25 | private static final int PRECEDENCE = 900; 26 | private static final String BUNDLE_NAME = "PageSizeSelector"; 27 | private static final String SELECTOR_VALUES = "page.size.selector.values"; 28 | private final List selectorValues = new ArrayList(); 29 | 30 | PageSizeSelectorAttrProcessor(final String dialectPrefix) { 31 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 32 | } 33 | 34 | @Override 35 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 36 | String attributeValue, IElementTagStructureHandler structureHandler) { 37 | 38 | Locale locale = context.getLocale(); 39 | loadSelectorValues(locale); 40 | String selectorStyle = String.valueOf(attributeValue).trim(); 41 | String messageKey = getMessageKey(selectorStyle); 42 | String options = composeSelectorOptions(selectorStyle, context); 43 | String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, options); 44 | 45 | structureHandler.setBody(message, false); 46 | } 47 | 48 | private void loadSelectorValues(Locale locale) { 49 | if (selectorValues.isEmpty()) { 50 | String property = Messages.getMessage(BUNDLE_NAME, SELECTOR_VALUES, locale); 51 | String[] values = property.split(Strings.COMMA); 52 | for (String value : values) { 53 | try { 54 | selectorValues.add(Integer.parseInt(value.trim())); 55 | } catch (Exception e) { 56 | LOGGER.error("Invalid page size value: {}", value, e); 57 | } 58 | } 59 | } 60 | } 61 | 62 | private String getMessageKey(String selectorStyle) { 63 | return Strings.EMPTY.equals(selectorStyle) ? DEFAULT_STYLE : MESSAGE_PREFIX.concat(selectorStyle); 64 | } 65 | 66 | /** 67 | * Create select html content, list of options 68 | * 69 | * @param selectorStyle 70 | * html selector style 71 | * @param context 72 | * execution context 73 | * @return available page size options as html 74 | */ 75 | private String composeSelectorOptions(String selectorStyle, ITemplateContext context) { 76 | Page page = PageUtils.findPage(context); 77 | int currentPageSize = page.getSize(); 78 | Locale locale = context.getLocale(); 79 | StringBuilder sb = new StringBuilder(); 80 | for (int value : selectorValues) { 81 | String url = PageUtils.createPageSizeUrl(context, value); 82 | boolean isSelectedValue = value == currentPageSize; 83 | String messageKey = getMessageKey(selectorStyle).concat(isSelectedValue ? ".option.selected" : ".option"); 84 | String option = Messages.getMessage(BUNDLE_NAME, messageKey, locale, value, url); 85 | sb.append(option); 86 | } 87 | 88 | return sb.toString(); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.thymeleaf.context.ITemplateContext; 4 | import org.thymeleaf.dialect.springdata.decorator.PaginationDecorator; 5 | import org.thymeleaf.dialect.springdata.decorator.PaginationDecoratorRegistry; 6 | import org.thymeleaf.dialect.springdata.util.Strings; 7 | import org.thymeleaf.engine.AttributeName; 8 | import org.thymeleaf.model.IProcessableElementTag; 9 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 10 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 11 | import org.thymeleaf.templatemode.TemplateMode; 12 | 13 | final class PaginationAttrProcessor extends AbstractAttributeTagProcessor { 14 | private static final String PAGINATION = "pagination"; 15 | public static final int PRECEDENCE = 1000; 16 | 17 | public PaginationAttrProcessor(final String dialectPrefix) { 18 | super(TemplateMode.HTML, dialectPrefix, null, false, PAGINATION, true, PRECEDENCE, true); 19 | } 20 | 21 | @Override 22 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 23 | String attributeValue, IElementTagStructureHandler structureHandler) { 24 | 25 | String attrValue = String.valueOf(attributeValue).trim(); 26 | PaginationDecorator decorator = PaginationDecoratorRegistry.getInstance().getDecorator(attrValue); 27 | String html = decorator.decorate(tag, context); 28 | 29 | boolean isUlNode = Strings.UL.equalsIgnoreCase(tag.getElementCompleteName()); 30 | if (isUlNode) { 31 | structureHandler.replaceWith(html, false); 32 | } else { 33 | structureHandler.setBody(html, false); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationQualifierAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.thymeleaf.context.ITemplateContext; 4 | import org.thymeleaf.context.WebEngineContext; 5 | import org.thymeleaf.engine.AttributeName; 6 | import org.thymeleaf.model.IProcessableElementTag; 7 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 8 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 9 | import org.thymeleaf.templatemode.TemplateMode; 10 | 11 | final class PaginationQualifierAttrProcessor extends AbstractAttributeTagProcessor { 12 | private static final String ATTR_NAME = "pagination-qualifier"; 13 | public static final int PRECEDENCE = 900; 14 | 15 | protected PaginationQualifierAttrProcessor(final String dialectPrefix) { 16 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 17 | } 18 | 19 | @Override 20 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 21 | String attributeValue, IElementTagStructureHandler structureHandler) { 22 | 23 | if (context instanceof WebEngineContext) { 24 | String attrValue = String.valueOf(attributeValue).trim(); 25 | ((WebEngineContext) context).setVariable(Keys.PAGINATION_QUALIFIER_PREFIX, attrValue); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSortAscAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.springframework.data.domain.Sort.Direction; 4 | 5 | final class PaginationSortAscAttrProcessor extends PaginationSortBaseAttrProcessor { 6 | private static final String ATTR_NAME = "pagination-sort-asc"; 7 | public static final int PRECEDENCE = 1000; 8 | 9 | public PaginationSortAscAttrProcessor(final String dialectPrefix) { 10 | super(dialectPrefix, ATTR_NAME, PRECEDENCE); 11 | } 12 | 13 | protected Direction getForcedDirection() { 14 | return Direction.ASC; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSortAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.springframework.data.domain.Sort.Direction; 4 | 5 | final class PaginationSortAttrProcessor extends PaginationSortBaseAttrProcessor { 6 | private static final String ATTR_NAME = "pagination-sort"; 7 | public static final int PRECEDENCE = 1000; 8 | 9 | public PaginationSortAttrProcessor(final String dialectPrefix) { 10 | super(dialectPrefix, ATTR_NAME, PRECEDENCE); 11 | } 12 | 13 | protected Direction getForcedDirection() { 14 | return null; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSortBaseAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Sort; 5 | import org.springframework.data.domain.Sort.Direction; 6 | import org.thymeleaf.context.ITemplateContext; 7 | import org.thymeleaf.dialect.springdata.util.Expressions; 8 | import org.thymeleaf.dialect.springdata.util.PageUtils; 9 | import org.thymeleaf.dialect.springdata.util.Strings; 10 | import org.thymeleaf.engine.AttributeName; 11 | import org.thymeleaf.model.IProcessableElementTag; 12 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 13 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 14 | import org.thymeleaf.templatemode.TemplateMode; 15 | 16 | import static org.thymeleaf.dialect.springdata.util.Strings.*; 17 | 18 | abstract class PaginationSortBaseAttrProcessor extends AbstractAttributeTagProcessor { 19 | public PaginationSortBaseAttrProcessor(final String dialectPrefix, final String attrName, final int precedence) { 20 | super(TemplateMode.HTML, dialectPrefix, null, false, attrName, true, precedence, true); 21 | } 22 | 23 | @Override 24 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 25 | String attributeValue, IElementTagStructureHandler structureHandler) { 26 | 27 | String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim(); 28 | Page page = PageUtils.findPage(context); 29 | String url = PageUtils.createSortUrl(context, attrValue, getForcedDirection()); 30 | 31 | // Append class to the element if sorted by this field 32 | Sort sort = page.getSort(); 33 | boolean isSorted = sort != null && sort.getOrderFor(attrValue) != null; 34 | String clas = isSorted 35 | ? SORTED_PREFIX.concat(sort.getOrderFor(attrValue).getDirection().toString().toLowerCase()) 36 | : EMPTY; 37 | 38 | structureHandler.setAttribute(HREF, url); 39 | String currentClass = tag.getAttributeValue(CLASS); 40 | structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas)); 41 | } 42 | 43 | /** 44 | * Optional "forced" sort direction, if sorting in only one direction is allowed. 45 | * @return null if sorting in either direction is allowed, otherwise specific direction 46 | */ 47 | protected abstract Direction getForcedDirection(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSortDescAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.springframework.data.domain.Sort.Direction; 4 | 5 | final class PaginationSortDescAttrProcessor extends PaginationSortBaseAttrProcessor { 6 | private static final String ATTR_NAME = "pagination-sort-desc"; 7 | public static final int PRECEDENCE = 1000; 8 | 9 | public PaginationSortDescAttrProcessor(final String dialectPrefix) { 10 | super(dialectPrefix, ATTR_NAME, PRECEDENCE); 11 | } 12 | 13 | protected Direction getForcedDirection() { 14 | return Direction.DESC; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSplitAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.thymeleaf.context.ITemplateContext; 4 | import org.thymeleaf.context.WebEngineContext; 5 | import org.thymeleaf.dialect.springdata.util.Expressions; 6 | import org.thymeleaf.engine.AttributeName; 7 | import org.thymeleaf.model.IProcessableElementTag; 8 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 9 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 10 | import org.thymeleaf.templatemode.TemplateMode; 11 | 12 | final class PaginationSplitAttrProcessor extends AbstractAttributeTagProcessor { 13 | private static final String ATTR_NAME = "pagination-split"; 14 | public static final int PRECEDENCE = 900; 15 | 16 | protected PaginationSplitAttrProcessor(final String dialectPrefix) { 17 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 18 | } 19 | 20 | @Override 21 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 22 | String attributeValue, IElementTagStructureHandler structureHandler) { 23 | 24 | if (context instanceof WebEngineContext) { 25 | Number split = (Number) Expressions.evaluate(context, attributeValue); 26 | ((WebEngineContext) context).setVariable(Keys.PAGINATION_SPLIT_KEY, split.intValue()); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationSummaryAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import java.util.Locale; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.thymeleaf.context.ITemplateContext; 7 | import org.thymeleaf.dialect.springdata.util.Messages; 8 | import org.thymeleaf.dialect.springdata.util.PageUtils; 9 | import org.thymeleaf.engine.AttributeName; 10 | import org.thymeleaf.model.IProcessableElementTag; 11 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 12 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 13 | import org.thymeleaf.templatemode.TemplateMode; 14 | 15 | final class PaginationSummaryAttrProcessor extends AbstractAttributeTagProcessor { 16 | private static final String COMPACT = "compact"; 17 | private static final String DEFAULT_MESSAGE_KEY = "pagination.summary"; 18 | private static final String COMPACT_MESSAGE_KEY = "pagination.summary.compact"; 19 | private static final String NO_VALUES_MESSAGE_KEY = "pagination.summary.empty"; 20 | private static final String ATTR_NAME = "pagination-summary"; 21 | public static final int PRECEDENCE = 900; 22 | private static final String BUNDLE_NAME = "PaginationSummary"; 23 | 24 | protected PaginationSummaryAttrProcessor(final String dialectPrefix) { 25 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 26 | } 27 | 28 | @Override 29 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 30 | String attributeValue, IElementTagStructureHandler structureHandler) { 31 | 32 | // Compose message with parameters: 33 | // {0} first reg. position 34 | // {1} latest page reg. position 35 | // {2} total elements 36 | // pagination.summary=Showing {0} to {1} of {2} entries 37 | 38 | Locale locale = context.getLocale(); 39 | Page page = PageUtils.findPage(context); 40 | int firstItem = PageUtils.getFirstItemInPage(page); 41 | int latestItem = PageUtils.getLatestItemInPage(page); 42 | int totalElements = (int) page.getTotalElements(); 43 | boolean isEmpty = page.getTotalElements() == 0; 44 | 45 | String attrValue = String.valueOf(attributeValue).trim(); 46 | String messageTemplate = COMPACT.equals(attrValue) ? COMPACT_MESSAGE_KEY : DEFAULT_MESSAGE_KEY; 47 | String messageKey = isEmpty ? NO_VALUES_MESSAGE_KEY : messageTemplate; 48 | String message = Messages.getMessage(BUNDLE_NAME, messageKey, locale, firstItem, latestItem, totalElements); 49 | 50 | structureHandler.setBody(message, false); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/PaginationUrlAttrProcessor.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import org.thymeleaf.context.ITemplateContext; 4 | import org.thymeleaf.context.WebEngineContext; 5 | import org.thymeleaf.dialect.springdata.util.Expressions; 6 | import org.thymeleaf.engine.AttributeName; 7 | import org.thymeleaf.model.IProcessableElementTag; 8 | import org.thymeleaf.processor.element.AbstractAttributeTagProcessor; 9 | import org.thymeleaf.processor.element.IElementTagStructureHandler; 10 | import org.thymeleaf.templatemode.TemplateMode; 11 | 12 | final class PaginationUrlAttrProcessor extends AbstractAttributeTagProcessor { 13 | private static final String ATTR_NAME = "pagination-url"; 14 | public static final int PRECEDENCE = 900; 15 | 16 | protected PaginationUrlAttrProcessor(final String dialectPrefix) { 17 | super(TemplateMode.HTML, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true); 18 | } 19 | 20 | @Override 21 | protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, 22 | String attributeValue, IElementTagStructureHandler structureHandler) { 23 | 24 | if (context instanceof WebEngineContext) { 25 | Object url = Expressions.evaluate(context, attributeValue); 26 | ((WebEngineContext) context).setVariable(Keys.PAGINATION_URL_KEY, url); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/SpringDataDialect.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.thymeleaf.dialect.IProcessorDialect; 7 | import org.thymeleaf.processor.IProcessor; 8 | import org.thymeleaf.standard.processor.StandardXmlNsTagProcessor; 9 | import org.thymeleaf.templatemode.TemplateMode; 10 | 11 | public final class SpringDataDialect implements IProcessorDialect { 12 | public static final String PREFIX = "sd"; 13 | public static final String NAME = "SpringDataDialect"; 14 | public static final int PRECEDENCE = 1000; 15 | 16 | public String getName() { 17 | return NAME; 18 | } 19 | 20 | public String getPrefix() { 21 | return PREFIX; 22 | } 23 | 24 | public int getDialectProcessorPrecedence() { 25 | return PRECEDENCE; 26 | } 27 | 28 | public Set getProcessors(final String dialectPrefix) { 29 | final Set processors = new HashSet(); 30 | processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML, PREFIX)); 31 | processors.add(new PaginationAttrProcessor(PREFIX)); 32 | processors.add(new PaginationSortAttrProcessor(PREFIX)); 33 | processors.add(new PaginationSortAscAttrProcessor(PREFIX)); 34 | processors.add(new PaginationSortDescAttrProcessor(PREFIX)); 35 | processors.add(new PaginationSummaryAttrProcessor(PREFIX)); 36 | processors.add(new PageObjectAttrProcessor(PREFIX)); 37 | processors.add(new PaginationUrlAttrProcessor(PREFIX)); 38 | processors.add(new PaginationQualifierAttrProcessor(PREFIX)); 39 | processors.add(new PaginationSplitAttrProcessor(PREFIX)); 40 | processors.add(new PageSizeSelectorAttrProcessor(PREFIX)); 41 | 42 | return processors; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/AbstractPagerDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | import java.util.Locale; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.thymeleaf.context.ITemplateContext; 7 | import org.thymeleaf.dialect.springdata.util.Messages; 8 | import org.thymeleaf.dialect.springdata.util.PageUtils; 9 | import org.thymeleaf.dialect.springdata.util.Strings; 10 | import org.thymeleaf.model.IProcessableElementTag; 11 | 12 | abstract class AbstractPagerDecorator implements PaginationDecorator { 13 | 14 | public final String decorate(final IProcessableElementTag tag, final ITemplateContext context) { 15 | String bundleName = getClass().getSimpleName(); 16 | Locale locale = context.getLocale(); 17 | Page page = PageUtils.findPage(context); 18 | 19 | // previous 20 | String previousPage = PageUtils.createPageUrl(context, page.getNumber() - 1); 21 | String prevKey = PageUtils.isFirstPage(page) ? "pager.previous" : "pager.previous.link"; 22 | String prev = Messages.getMessage(bundleName, prevKey, locale, previousPage); 23 | 24 | // next 25 | String nextPage = PageUtils.createPageUrl(context, page.getNumber() + 1); 26 | String nextKey = page.isLast() ? "pager.next" : "pager.next.link"; 27 | String next = Messages.getMessage(bundleName, nextKey, locale, nextPage); 28 | 29 | String content = Strings.concat(prev, next); 30 | 31 | return Messages.getMessage(bundleName, "pager", locale, content); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/AlignedLinksDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | public final class AlignedLinksDecorator extends AbstractPagerDecorator { 4 | 5 | public String getIdentifier() { 6 | return "aligned-links"; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/CompactPagerDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | public class CompactPagerDecorator extends AbstractPagerDecorator { 4 | 5 | @Override 6 | public String getIdentifier() { 7 | return "compact-pager"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/FullPaginationDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | import java.util.Locale; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.thymeleaf.context.ITemplateContext; 7 | import org.thymeleaf.dialect.springdata.Keys; 8 | import org.thymeleaf.dialect.springdata.util.Messages; 9 | import org.thymeleaf.dialect.springdata.util.PageUtils; 10 | import org.thymeleaf.dialect.springdata.util.Strings; 11 | import org.thymeleaf.model.IProcessableElementTag; 12 | 13 | public final class FullPaginationDecorator implements PaginationDecorator { 14 | private static final String DEFAULT_CLASS = "pagination"; 15 | private static final String BUNDLE_NAME = FullPaginationDecorator.class.getSimpleName(); 16 | private static final int DEFAULT_PAGE_SPLIT = 7; 17 | 18 | public String getIdentifier() { 19 | return "full"; 20 | } 21 | 22 | public String decorate(final IProcessableElementTag tag, final ITemplateContext context) { 23 | 24 | Page page = PageUtils.findPage(context); 25 | 26 | // laquo 27 | String firstPage = PageUtils.createPageUrl(context, 0); 28 | Locale locale = context.getLocale(); 29 | String laquo = PageUtils.isFirstPage(page) ? getLaquo(locale) : getLaquo(firstPage, locale); 30 | 31 | // Previous page 32 | String previous = getPreviousPageLink(page, context); 33 | 34 | // Links 35 | String pageLinks = createPageLinks(page, context); 36 | 37 | // Next page 38 | String next = getNextPageLink(page, context); 39 | 40 | // raquo 41 | String lastPage = PageUtils.createPageUrl(context, page.getTotalPages() - 1); 42 | String raquo = page.isLast() ? getRaquo(locale) : getRaquo(lastPage, locale); 43 | 44 | boolean isUl = Strings.UL.equalsIgnoreCase(tag.getElementCompleteName()); 45 | String currentClass = tag.getAttributeValue(Strings.CLASS); 46 | String clas = (isUl && !Strings.isEmpty(currentClass)) ? currentClass : DEFAULT_CLASS; 47 | 48 | return Messages.getMessage(BUNDLE_NAME, "pagination", locale, clas, laquo, previous, pageLinks, next, raquo); 49 | } 50 | 51 | private String createPageLinks(final Page page, final ITemplateContext context) { 52 | if( page.getTotalElements()==0 ){ 53 | return Strings.EMPTY; 54 | } 55 | 56 | int pageSplit = DEFAULT_PAGE_SPLIT; 57 | Object paramValue = context.getVariable(Keys.PAGINATION_SPLIT_KEY); 58 | if (paramValue != null) { 59 | pageSplit = (Integer) paramValue; 60 | } 61 | 62 | int firstPage = 0; 63 | int latestPage = page.getTotalPages(); 64 | int currentPage = page.getNumber(); 65 | if (latestPage >= pageSplit) { 66 | // Total pages > than split value, create links to split value 67 | int pageDiff = latestPage - currentPage; 68 | if (currentPage == 0) { 69 | // From first page to split value 70 | latestPage = pageSplit; 71 | } else if (pageDiff < pageSplit) { 72 | // From split value to latest page 73 | firstPage = currentPage - (pageSplit - pageDiff); 74 | } else { 75 | // From current page -1 to split value 76 | firstPage = currentPage - 1; 77 | latestPage = currentPage + pageSplit - 1; 78 | } 79 | } 80 | 81 | StringBuilder builder = new StringBuilder(); 82 | // Page links 83 | for (int i = firstPage; i < latestPage; i++) { 84 | int pageNumber = i + 1; 85 | String link = PageUtils.createPageUrl(context, i); 86 | boolean isCurrentPage = i == currentPage; 87 | Locale locale = context.getLocale(); 88 | String li = isCurrentPage ? getLink(pageNumber, locale) : getLink(pageNumber, link, locale); 89 | builder.append(li); 90 | } 91 | 92 | return builder.toString(); 93 | } 94 | 95 | private String getLaquo(Locale locale) { 96 | return Messages.getMessage(BUNDLE_NAME, "laquo", locale); 97 | } 98 | 99 | private String getLaquo(String firstPage, Locale locale) { 100 | return Messages.getMessage(BUNDLE_NAME, "laquo.link", locale, firstPage); 101 | } 102 | 103 | private String getRaquo(Locale locale) { 104 | return Messages.getMessage(BUNDLE_NAME, "raquo", locale); 105 | } 106 | 107 | private String getRaquo(String lastPage, Locale locale) { 108 | return Messages.getMessage(BUNDLE_NAME, "raquo.link", locale, lastPage); 109 | } 110 | 111 | private String getLink(int pageNumber, Locale locale) { 112 | return Messages.getMessage(BUNDLE_NAME, "link.active", locale, pageNumber); 113 | } 114 | 115 | private String getLink(int pageNumber, String url, Locale locale) { 116 | return Messages.getMessage(BUNDLE_NAME, "link", locale, url, pageNumber); 117 | } 118 | 119 | private String getPreviousPageLink(Page page, final ITemplateContext context) { 120 | String msgKey = PageUtils.hasPrevious(page) ? "previous.page.link" : "previous.page"; 121 | Locale locale = context.getLocale(); 122 | int previousPage = page.getNumber()-1; 123 | String link = PageUtils.createPageUrl(context, previousPage); 124 | 125 | return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link); 126 | } 127 | 128 | private String getNextPageLink(Page page, final ITemplateContext context) { 129 | String msgKey = page.hasNext() ? "next.page.link" : "next.page"; 130 | Locale locale = context.getLocale(); 131 | int nextPage = page.getNumber() + 1; 132 | String link = PageUtils.createPageUrl(context, nextPage); 133 | 134 | return Messages.getMessage(BUNDLE_NAME, msgKey, locale, link); 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/PagerDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | public class PagerDecorator extends AbstractPagerDecorator { 4 | 5 | public String getIdentifier() { 6 | return "pager"; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/PaginationDecorator.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | import org.thymeleaf.context.ITemplateContext; 4 | import org.thymeleaf.model.IProcessableElementTag; 5 | 6 | public interface PaginationDecorator { 7 | 8 | String getIdentifier(); 9 | 10 | String decorate(IProcessableElementTag tag, ITemplateContext context); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/decorator/PaginationDecoratorRegistry.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.decorator; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.ServiceLoader; 6 | 7 | import org.thymeleaf.dialect.springdata.exception.PaginationDecoratorNotFoundException; 8 | 9 | public final class PaginationDecoratorRegistry { 10 | private static final PaginationDecoratorRegistry INSTANCE = new PaginationDecoratorRegistry(); 11 | private final Map availableDecorators; 12 | 13 | private PaginationDecoratorRegistry() { 14 | 15 | final ServiceLoader loader = ServiceLoader.load(PaginationDecorator.class); 16 | availableDecorators = new HashMap(); 17 | 18 | for (PaginationDecorator decorator : loader) { 19 | availableDecorators.put(decorator.getIdentifier(), decorator); 20 | } 21 | } 22 | 23 | public static PaginationDecoratorRegistry getInstance() { 24 | return INSTANCE; 25 | } 26 | 27 | public PaginationDecorator getDecorator(String identifier) throws PaginationDecoratorNotFoundException { 28 | if (!availableDecorators.containsKey(identifier)) { 29 | throw new PaginationDecoratorNotFoundException( 30 | "Pagination decorator with identifier: " + identifier + " not found!"); 31 | } 32 | 33 | return availableDecorators.get(identifier); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/exception/InvalidObjectParameterException.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.exception; 2 | 3 | public class InvalidObjectParameterException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public InvalidObjectParameterException(String msg) { 7 | super(msg); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/exception/PaginationDecoratorNotFoundException.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.exception; 2 | 3 | public class PaginationDecoratorNotFoundException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public PaginationDecoratorNotFoundException(String message) { 7 | super(message); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/util/Expressions.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.util; 2 | 3 | import org.thymeleaf.context.IExpressionContext; 4 | import org.thymeleaf.standard.expression.IStandardExpression; 5 | import org.thymeleaf.standard.expression.IStandardExpressionParser; 6 | import org.thymeleaf.standard.expression.StandardExpressions; 7 | 8 | public final class Expressions { 9 | 10 | public Expressions() { 11 | } 12 | 13 | public static Object evaluate(IExpressionContext context, String expressionValue) { 14 | final String value = String.valueOf(expressionValue).trim(); 15 | final IStandardExpressionParser expressionParser = StandardExpressions 16 | .getExpressionParser(context.getConfiguration()); 17 | final IStandardExpression expression = expressionParser.parseExpression(context, value); 18 | 19 | return expression.execute(context); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/util/Messages.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.util; 2 | 3 | import java.text.MessageFormat; 4 | import java.util.Collections; 5 | import java.util.Locale; 6 | import java.util.ResourceBundle; 7 | 8 | public final class Messages { 9 | private static final String BASE_PATH = "thymeleaf-spring-data-dialect/"; 10 | 11 | private Messages() { 12 | } 13 | 14 | public static String getMessage(String bundleName, String key, Locale locale, Object... arguments) { 15 | final String resourceName = Strings.concat(BASE_PATH, bundleName); 16 | final String msg = ResourceBundle.getBundle(resourceName, locale).getString(key); 17 | 18 | return MessageFormat.format(msg, arguments); 19 | } 20 | 21 | public static String getMessage(String bundleName, String key, Locale locale) { 22 | return getMessage(bundleName, key, locale, Collections.EMPTY_LIST); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/util/PageUtils.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.util; 2 | 3 | import static org.thymeleaf.dialect.springdata.util.Strings.AND; 4 | import static org.thymeleaf.dialect.springdata.util.Strings.COMMA; 5 | import static org.thymeleaf.dialect.springdata.util.Strings.EMPTY; 6 | import static org.thymeleaf.dialect.springdata.util.Strings.EQ; 7 | import static org.thymeleaf.dialect.springdata.util.Strings.PAGE; 8 | import static org.thymeleaf.dialect.springdata.util.Strings.Q_MARK; 9 | import static org.thymeleaf.dialect.springdata.util.Strings.SIZE; 10 | import static org.thymeleaf.dialect.springdata.util.Strings.SORT; 11 | 12 | import java.util.Arrays; 13 | import java.util.Collection; 14 | import java.util.Iterator; 15 | import java.util.Map; 16 | import java.util.Map.Entry; 17 | import java.util.Set; 18 | 19 | import org.springframework.data.domain.Page; 20 | import org.springframework.data.domain.Sort; 21 | import org.springframework.data.domain.Sort.Direction; 22 | import org.springframework.data.domain.Sort.Order; 23 | import org.thymeleaf.IEngineConfiguration; 24 | import org.thymeleaf.context.ITemplateContext; 25 | import org.thymeleaf.context.IWebContext; 26 | import org.thymeleaf.dialect.springdata.Keys; 27 | import org.thymeleaf.dialect.springdata.exception.InvalidObjectParameterException; 28 | import org.thymeleaf.standard.expression.IStandardExpression; 29 | import org.thymeleaf.standard.expression.IStandardExpressionParser; 30 | import org.thymeleaf.standard.expression.StandardExpressions; 31 | import org.thymeleaf.web.IWebExchange; 32 | import org.thymeleaf.web.IWebRequest; 33 | import org.thymeleaf.web.servlet.IServletWebRequest; 34 | import org.unbescape.html.HtmlEscape; 35 | 36 | @SuppressWarnings("unchecked") 37 | public final class PageUtils { 38 | 39 | private PageUtils() { 40 | } 41 | 42 | public static Page findPage(final ITemplateContext context) { 43 | // 1. Get Page object from local variables (defined with sd:page-object) 44 | // 2. Search Page using ${page} expression 45 | // 3. Search Page object as request attribute 46 | 47 | final Object pageFromLocalVariable = context.getVariable(Keys.PAGE_VARIABLE_KEY); 48 | if (isPageInstance(pageFromLocalVariable)) { 49 | return (Page) pageFromLocalVariable; 50 | } 51 | 52 | // Check if not null and Page instance available with ${page} expression 53 | final IEngineConfiguration configuration = context.getConfiguration(); 54 | final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration); 55 | final IStandardExpression expression = parser.parseExpression(context, Keys.PAGE_EXPRESSION); 56 | final Object page = expression.execute(context); 57 | if (isPageInstance(page)) { 58 | return (Page) page; 59 | } 60 | 61 | // Search for Page object, and only one instance, as request attribute 62 | if (context instanceof IWebContext) { 63 | IWebExchange webExchange = ((IWebContext) context).getExchange(); 64 | Set attrNames = webExchange.getAllAttributeNames(); 65 | Page pageOnRequest = null; 66 | 67 | for (String attrName : attrNames) { 68 | Object attr = webExchange.getAttributeValue(attrName); 69 | if (isPageInstance(attr)) { 70 | if (pageOnRequest != null) { 71 | throw new InvalidObjectParameterException("More than one Page object found on request!"); 72 | } 73 | 74 | pageOnRequest = (Page) attr; 75 | } 76 | } 77 | 78 | if (pageOnRequest != null) { 79 | return pageOnRequest; 80 | } 81 | } 82 | 83 | throw new InvalidObjectParameterException("Invalid or not present Page object found on request!"); 84 | } 85 | 86 | public static String createPageUrl(final ITemplateContext context, int pageNumber) { 87 | final String prefix = getParamPrefix(context); 88 | final Collection excludedParams = Arrays.asList(new String[] { prefix.concat(PAGE) }); 89 | final String baseUrl = buildBaseUrl(context, excludedParams); 90 | 91 | return buildUrl(baseUrl, context).append(PAGE).append(EQ).append(pageNumber).toString(); 92 | } 93 | 94 | /** 95 | * Creates an url to sort data by fieldName 96 | * 97 | * @param context execution context 98 | * @param fieldName field name to sort 99 | * @param forcedDir optional, if specified then only this sort direction will be allowed 100 | * @return sort URL 101 | */ 102 | public static String createSortUrl(final ITemplateContext context, final String fieldName, final Direction forcedDir) { 103 | // Params can be prefixed to manage multiple pagination on the same page 104 | final String prefix = getParamPrefix(context); 105 | final Collection excludedParams = Arrays 106 | .asList(new String[] { prefix.concat(SORT), prefix.concat(PAGE) }); 107 | final String baseUrl = buildBaseUrl(context, excludedParams); 108 | 109 | final StringBuilder sortParam = new StringBuilder(); 110 | final Page page = findPage(context); 111 | final Sort sort = page.getSort(); 112 | final boolean hasPreviousOrder = sort != null && sort.getOrderFor(fieldName) != null; 113 | if (forcedDir != null) { 114 | sortParam.append(fieldName).append(COMMA).append(forcedDir.toString().toLowerCase()); 115 | } else if (hasPreviousOrder) { 116 | // Sort parameters exists for this field, modify direction 117 | Order previousOrder = sort.getOrderFor(fieldName); 118 | Direction dir = previousOrder.isAscending() ? Direction.DESC : Direction.ASC; 119 | sortParam.append(fieldName).append(COMMA).append(dir.toString().toLowerCase()); 120 | } else { 121 | sortParam.append(fieldName); 122 | } 123 | 124 | return buildUrl(baseUrl, context).append(SORT).append(EQ).append(sortParam).toString(); 125 | } 126 | 127 | public static String createPageSizeUrl(final ITemplateContext context, int pageSize) { 128 | final String prefix = getParamPrefix(context); 129 | // Reset page number to avoid empty lists 130 | final Collection excludedParams = Arrays 131 | .asList(new String[] { prefix.concat(SIZE), prefix.concat(PAGE) }); 132 | final String baseUrl = buildBaseUrl(context, excludedParams); 133 | 134 | return buildUrl(baseUrl, context).append(SIZE).append(EQ).append(pageSize).toString(); 135 | } 136 | 137 | public static int getFirstItemInPage(final Page page) { 138 | return page.getSize() * page.getNumber() + 1; 139 | } 140 | 141 | public static int getLatestItemInPage(final Page page) { 142 | return page.getSize() * page.getNumber() + page.getNumberOfElements(); 143 | } 144 | 145 | public static boolean isFirstPage(Page page) { 146 | if( page.getTotalPages()==0 ) { 147 | return true; 148 | } 149 | 150 | return page.isFirst(); 151 | } 152 | 153 | public static boolean hasPrevious(Page page) { 154 | return page.getTotalPages()>0 && page.hasPrevious(); 155 | } 156 | 157 | private static String buildBaseUrl(final ITemplateContext context, Collection excludeParams) { 158 | // URL defined with pagination-url tag 159 | final String url = (String) context.getVariable(Keys.PAGINATION_URL_KEY); 160 | 161 | if (url == null && context instanceof IWebContext) { 162 | // Creates url from actual request URI and parameters 163 | final StringBuilder builder = new StringBuilder(); 164 | final IWebContext webContext = (IWebContext) context; 165 | final IWebExchange webExchange = webContext.getExchange(); 166 | final IWebRequest request = webExchange.getRequest(); 167 | 168 | // URL base path from request 169 | builder.append(getRequestURI(request)); 170 | 171 | Map params = request.getParameterMap(); 172 | Set> entries = params.entrySet(); 173 | boolean firstParam = true; 174 | for (Entry param : entries) { 175 | // Append params not excluded to basePath 176 | String name = param.getKey(); 177 | if (!excludeParams.contains(name)) { 178 | if (firstParam) { 179 | builder.append(Q_MARK); 180 | firstParam = false; 181 | } else { 182 | builder.append(AND); 183 | } 184 | 185 | // Iterate over all values to create multiple values per 186 | // parameter 187 | String[] values = param.getValue(); 188 | Collection paramValues = Arrays.asList(values); 189 | Iterator it = paramValues.iterator(); 190 | while (it.hasNext()) { 191 | String value = it.next(); 192 | builder.append(name).append(EQ).append(value); 193 | if (it.hasNext()) { 194 | builder.append(AND); 195 | } 196 | } 197 | } 198 | } 199 | 200 | // Escape to HTML content 201 | return HtmlEscape.escapeHtml4Xml(builder.toString()); 202 | } 203 | 204 | return url == null ? EMPTY : url; 205 | } 206 | 207 | private static String getRequestURI(IWebRequest webRequest) { 208 | if (webRequest instanceof IServletWebRequest servletWebRequest) { 209 | return servletWebRequest.getRequestURI(); 210 | } else { 211 | // from org.thymeleaf.web.IWebRequest.getRequestURL 212 | String scheme = webRequest.getScheme(); 213 | String serverName = webRequest.getServerName(); 214 | Integer serverPort = webRequest.getServerPort(); 215 | String requestPath = webRequest.getRequestPath(); 216 | if (scheme != null && serverName != null && serverPort != null) { 217 | StringBuilder urlBuilder = new StringBuilder(); 218 | urlBuilder.append(scheme).append("://").append(serverName); 219 | if ((!scheme.equals("http") || serverPort != 80) && (!scheme.equals("https") || serverPort != 443)) { 220 | urlBuilder.append(':').append(serverPort); 221 | } 222 | 223 | urlBuilder.append(requestPath); 224 | 225 | return urlBuilder.toString(); 226 | } else { 227 | throw new UnsupportedOperationException("Request scheme, server name or port are null in this environment. Cannot compute request URL"); 228 | } 229 | } 230 | } 231 | 232 | private static boolean isPageInstance(Object page) { 233 | return page != null && (page instanceof Page); 234 | } 235 | 236 | private static StringBuilder buildUrl(String baseUrl, final ITemplateContext context) { 237 | final String paramAppender = String.valueOf(baseUrl).contains(Q_MARK) ? AND : Q_MARK; 238 | final String prefix = getParamPrefix(context); 239 | 240 | return new StringBuilder(baseUrl).append(paramAppender).append(prefix); 241 | } 242 | 243 | private static String getParamPrefix(final ITemplateContext context) { 244 | final String prefix = (String) context.getVariable(Keys.PAGINATION_QUALIFIER_PREFIX); 245 | 246 | return prefix == null ? EMPTY : prefix.concat("_"); 247 | } 248 | 249 | } 250 | -------------------------------------------------------------------------------- /src/main/java/org/thymeleaf/dialect/springdata/util/Strings.java: -------------------------------------------------------------------------------- 1 | package org.thymeleaf.dialect.springdata.util; 2 | 3 | public final class Strings { 4 | 5 | public static final String EMPTY = ""; 6 | public static final String BLANK = " "; 7 | public static final String CLASS = "class"; 8 | public static final String UL = "ul"; 9 | public static final String HREF = "href"; 10 | public static final String COMMA = ","; 11 | public static final String AND = "&"; 12 | public static final String Q_MARK = "?"; 13 | public static final String EQ = "="; 14 | public static final String PAGE = "page"; 15 | public static final String SIZE = "size"; 16 | public static final String SORTED_PREFIX = "sorted-"; 17 | public static final String SORT = "sort"; 18 | 19 | private Strings() { 20 | } 21 | 22 | public static String concat(String... strings) { 23 | final StringBuilder builder = new StringBuilder(); 24 | for (String string : strings) { 25 | builder.append(string); 26 | } 27 | 28 | return builder.toString(); 29 | } 30 | 31 | public static boolean isEmpty(String text) { 32 | return text == null || text.equals(EMPTY); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.thymeleaf.dialect.springdata.decorator.PaginationDecorator: -------------------------------------------------------------------------------- 1 | org.thymeleaf.dialect.springdata.decorator.FullPaginationDecorator 2 | org.thymeleaf.dialect.springdata.decorator.PagerDecorator 3 | org.thymeleaf.dialect.springdata.decorator.CompactPagerDecorator 4 | org.thymeleaf.dialect.springdata.decorator.AlignedLinksDecorator -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_de.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_en.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_es.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_fr.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_gl.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_it.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_nl.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= 6 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_pt.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_pt.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_ru.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_zh_CN.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/AlignedLinksDecorator_zh_TW.properties: -------------------------------------------------------------------------------- 1 | pager=
    {0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/CompactPagerDecorator.properties: -------------------------------------------------------------------------------- 1 | pager=
{0}
2 | pager.previous= 3 | pager.previous.link= 4 | pager.next= 5 | pager.next.link= -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
    {1}{2}{3}{4}{5}
3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(current)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_de.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_en.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
      {1}{2}{3}{4}{5}
    3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(current)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_es.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_es.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_fr.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_gl.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_gl.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_it.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
      {1}{2}{3}{4}{5}
    3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(corrente)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_nl.properties: -------------------------------------------------------------------------------- 1 | pagination=
      {1}{2}{3}{4}{5}
    2 | laquo=
  • 3 | laquo.link=
  • 4 | previous.page=
  • 5 | previous.page.link=
  • 6 | link=
  • {1}
  • 7 | link.active=
  • {0}(huidige)
  • 8 | next.page=
  • 9 | next.page.link=
  • 10 | raquo=
  • 11 | raquo.link=
  • 12 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_pt.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_pt.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_ru.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
      {1}{2}{3}{4}{5}
    3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(current)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_zh_CN.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
      {1}{2}{3}{4}{5}
    3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(current)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/FullPaginationDecorator_zh_TW.properties: -------------------------------------------------------------------------------- 1 | #pagination {0}=class, {1}=firstPage, {2}=previousPage, {3}=links, {4}=nextPage, {5}=latestPage 2 | pagination=
      {1}{2}{3}{4}{5}
    3 | laquo=
  • 4 | laquo.link=
  • 5 | previous.page=
  • 6 | previous.page.link=
  • 7 | link=
  • {1}
  • 8 | link.active=
  • {0}(current)
  • 9 | next.page=
  • 10 | next.page.link=
  • 11 | raquo=
  • 12 | raquo.link=
  • 13 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PageSizeSelector.properties: -------------------------------------------------------------------------------- 1 | page.size.selector.values=10,20,50,100 2 | page.size.selector.default= 3 | page.size.selector.default.option= 4 | page.size.selector.default.option.selected= 5 | page.size.selector.javascript= 6 | page.size.selector.javascript.option= 7 | page.size.selector.javascript.option.selected= 8 | page.size.selector.dropdown= 9 | page.size.selector.dropdown.option=
  • {0}
  • 10 | page.size.selector.dropdown.option.selected=
  • {0}
  • 11 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Previous
  • 3 | pager.previous.link=
  • Previous
  • 4 | pager.next=
  • Next
  • 5 | pager.next.link=
  • Next
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_de.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_en.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Previous
  • 3 | pager.previous.link=
  • Previous
  • 4 | pager.next=
  • Next
  • 5 | pager.next.link=
  • Next
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_es.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Anterior
  • 3 | pager.previous.link=
  • Anterior
  • 4 | pager.next=
  • Siguiente
  • 5 | pager.next.link=
  • Siguiente
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_fr.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_gl.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Anterior
  • 3 | pager.previous.link=
  • Anterior
  • 4 | pager.next=
  • Seguinte
  • 5 | pager.next.link=
  • Seguinte
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_it.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Precedente
  • 3 | pager.previous.link=
  • Precedente
  • 4 | pager.next=
  • Prossimo
  • 5 | pager.next.link=
  • Prossimo
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_nl.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • Vorige
  • 3 | pager.previous.link=
  • Vorige
  • 4 | pager.next=
  • Volgende
  • 5 | pager.next.link=
  • Volgende
  • 6 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_pt.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_pt.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_ru.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f
  • 3 | pager.previous.link=
  • \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f
  • 4 | pager.next=
  • \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f
  • 5 | pager.next.link=
  • \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_zh_CN.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • \u4E0A\u9875
  • 3 | pager.previous.link=
  • \u4E0A\u9875
  • 4 | pager.next=
  • \u4E0B\u9875
  • 5 | pager.next.link=
  • \u4E0B\u9875
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PagerDecorator_zh_TW.properties: -------------------------------------------------------------------------------- 1 | pager=
      {0}
    2 | pager.previous=
  • \u4E0A\u9801
  • 3 | pager.previous.link=
  • \u4E0A\u9801
  • 4 | pager.next=
  • \u4E0B\u9801
  • 5 | pager.next.link=
  • \u4E0B\u9801
  • -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=No results found 2 | pagination.summary=Showing {0} to {1} of {2} entries 3 | pagination.summary.compact={0}-{1} of {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_de.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_de.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_en.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=No results found 2 | pagination.summary=Showing {0} to {1} of {2} entries 3 | pagination.summary.compact={0}-{1} of {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_es.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=No se han encontrado resultados 2 | pagination.summary=Mostrando {0} al {1} de {2} resultados 3 | pagination.summary.compact={0}-{1} de {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_fr.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpenren/thymeleaf-spring-data-dialect/984e8d5f8a5a79fb19e13759f91973baac5f8af1/src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_fr.properties -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_gl.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=Non se atoparon resultados 2 | pagination.summary=Mostrando {0} ao {1} de {2} resultados 3 | pagination.summary.compact={0}-{1} de {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_it.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=Nessun risultato trovato 2 | pagination.summary=Mostrando {0} a {1} di {2} voci 3 | pagination.summary.compact={0}-{1} di {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_nl.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=Geen resultaten 2 | pagination.summary=Resultaten {0} tot {1} van {2} 3 | pagination.summary.compact={0}-{1} van {2} 4 | -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_pt.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=Nenhum resultado encontrado 2 | pagination.summary=Mostrando {0} para {1} de {2} entradas 3 | pagination.summary.compact={0}-{1} de {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_ru.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b 2 | pagination.summary=\u041f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441 {0} \u043f\u043e {1} \u0438\u0437 {2} \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 3 | pagination.summary.compact={0}-{1} \u0438\u0437 {2} -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_zh_CN.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=\u672A\u627E\u5230\u7ED3\u679C 2 | pagination.summary=\u5171{2}\u6761 \u663E\u793A\u7B2C{0}\u6761\u5230\u7B2C{1}\u6761 3 | pagination.summary.compact=\u7B2C{0}-{1}\u6761 \u5171{2}\u6761 -------------------------------------------------------------------------------- /src/main/resources/thymeleaf-spring-data-dialect/PaginationSummary_zh_TW.properties: -------------------------------------------------------------------------------- 1 | pagination.summary.empty=\u672A\u627E\u5230\u7D50\u679C 2 | pagination.summary=\u5171{2}\u689D \u986F\u793A\u7B2C{0}\u689D\u5230\u7B2C{1}\u689D 3 | pagination.summary.compact=\u7B2C{0}-{1}\u689D \u5171{2}\u689D --------------------------------------------------------------------------------