|
6 | 6 | import jakarta.validation.constraints.NotEmpty;
|
7 | 7 | import jakarta.validation.constraints.NotNull;
|
8 | 8 | import java.util.*;
|
9 |
| -import java.util.regex.Matcher; |
10 |
| -import java.util.regex.Pattern; |
11 | 9 |
|
12 | 10 | /**
|
13 | 11 | * The format of the payload sent by the client.
|
|
16 | 14 | */
|
17 | 15 | @Data
|
18 | 16 | public class DataTablesInput {
|
19 |
| - /** |
20 |
| - * Format: <code>searchPanes.$attribute.0</code> (<code>searchPanes[$attribute][0]</code> without jquery.spring-friendly.js) |
21 |
| - * |
22 |
| - * @see <a href="https://github.com/DataTables/SearchPanes/blob/5e6d3229cd90594cc67d6d266321f1c922fc9231/src/searchPanes.ts#L119-L137">source</a> |
23 |
| - */ |
24 |
| - private static final Pattern SEARCH_PANES_REGEX = Pattern.compile("^searchPanes\\.(\\w+)\\.\\d+$"); |
25 |
| - |
26 | 17 | /**
|
27 | 18 | * Draw counter. This is used by DataTables to ensure that the Ajax returns from server-side
|
28 | 19 | * processing requests are drawn in sequence by DataTables (Ajax requests are asynchronous and
|
@@ -137,17 +128,20 @@ public void addOrder(String columnName, boolean ascending) {
|
137 | 128 |
|
138 | 129 | public void parseSearchPanesFromQueryParams(Map<String, String> queryParams, Collection<String> attributes) {
|
139 | 130 | Map<String, Set<String>> searchPanes = new HashMap<>();
|
140 |
| - attributes.forEach(attribute -> searchPanes.put(attribute, new HashSet<>())); |
141 |
| - |
142 |
| - queryParams.forEach((key, value) -> { |
143 |
| - Matcher matcher = SEARCH_PANES_REGEX.matcher(key); |
144 |
| - if (matcher.matches()) { |
145 |
| - String attribute = matcher.group(1); |
146 |
| - if (attributes.contains(attribute)) { |
147 |
| - searchPanes.get(attribute).add(value); |
| 131 | + |
| 132 | + for (String attribute : attributes) { |
| 133 | + Set<String> values = new HashSet<>(); |
| 134 | + for (int i = 0; ; i++) { |
| 135 | + String paramName = "searchPanes." + attribute + "." + i; |
| 136 | + String paramValue = queryParams.get(paramName); |
| 137 | + if (paramValue != null) { |
| 138 | + values.add(paramValue); |
| 139 | + } else { |
| 140 | + break; |
148 | 141 | }
|
149 | 142 | }
|
150 |
| - }); |
| 143 | + searchPanes.put(attribute, values); |
| 144 | + } |
151 | 145 |
|
152 | 146 | this.searchPanes = searchPanes;
|
153 | 147 | }
|
|
0 commit comments