Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,15 @@ public void add(FilterComponent filterComponent) {
if (filterComponent instanceof PropertyFilter) {
// Keep the registration so remove() can detach it; otherwise re-adding a component
// (e.g. on a filter re-navigation restore) would accumulate stale apply() listeners.
// Apply on the user's gesture only: a programmatic operation change (e.g. the URL binder
// restoring the filter state) must not fire a load of its own, consistently with the
// value path, which is gated by isFromClient in SingleFilterComponentBase.
Registration operationChangeRegistration = ((PropertyFilter<?>) filterComponent)
.addOperationChangeListener(operationChangeEvent -> apply());
.addOperationChangeListener(operationChangeEvent -> {
if (operationChangeEvent.isFromClient()) {
apply();
}
});
operationChangeRegistrations.put(filterComponent, operationChangeRegistration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,11 @@ protected void applyPropertyFilterParameters(List<String> params) {

@SuppressWarnings({"rawtypes", "unchecked"})
protected void applyPropertyFilterParameter(String parameterString) {
int separatorIndex = parameterString.indexOf(SEPARATOR);
List<String> tokens = filterUrlQueryParametersSupport.splitParameter(parameterString, 3);

if (separatorIndex == -1) {
throw new IllegalStateException("Can't parse property condition: " + parameterString);
}

String keyString = parameterString.substring(0, separatorIndex);

parameterString = parameterString.substring(separatorIndex + 1);
separatorIndex = parameterString.indexOf(SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalStateException("Can't parse property condition: " + parameterString);
}

String propertyString = parameterString.substring(0, separatorIndex);
String keyString = tokens.get(0);
String property = urlParamSerializer.deserialize(String.class,
filterUrlQueryParametersSupport.restoreSeparatorValue(propertyString));
filterUrlQueryParametersSupport.restoreSeparatorValue(tokens.get(1)));

DataGridColumn<?> column = (DataGridColumn<?>) grid.getColumnByKey(keyString);
if (column == null) {
Expand All @@ -219,22 +207,15 @@ protected void applyPropertyFilterParameter(String parameterString) {
throw new IllegalStateException("Column must be filterable");
}

parameterString = parameterString.substring(separatorIndex + 1);
separatorIndex = parameterString.indexOf(SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalStateException("Can't parse property condition: " + parameterString);
}

String operationString = parameterString.substring(0, separatorIndex);
PropertyFilter.Operation operation = urlParamSerializer
.deserialize(PropertyFilter.Operation.class,
filterUrlQueryParametersSupport.restoreSeparatorValue(operationString));
filterUrlQueryParametersSupport.restoreSeparatorValue(tokens.get(2)));

DataGridHeaderFilter headerFilter = (DataGridHeaderFilter) column.getHeaderComponent();
PropertyFilter propertyFilter = headerFilter.getPropertyFilter();
propertyFilter.setOperation(operation);

String valueString = parameterString.substring(separatorIndex + 1);
String valueString = tokens.get(3);
if (!Strings.isNullOrEmpty(valueString)) {
try {
Object parsedValue = filterUrlQueryParametersSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import org.jspecify.annotations.Nullable;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -130,6 +132,33 @@ public Object parseCollectionValue(String property, String collectionValueString
.toList();
}

/**
* Splits a serialized parameter string into {@code headTokens} structural tokens separated by
* {@link #SEPARATOR}, plus the remainder — everything past the last structural separator. The
* remainder may itself contain separator characters (e.g. inside a serialized value) and may be
* empty. The returned list always has {@code headTokens + 1} elements.
*
* @param parameterString the serialized parameter string
* @param headTokens the number of structural tokens before the remainder
* @return the structural tokens followed by the remainder
* @throws IllegalStateException if the string has fewer than {@code headTokens} separators
*/
public List<String> splitParameter(String parameterString, int headTokens) {
List<String> tokens = new ArrayList<>(headTokens + 1);
String rest = parameterString;
for (int i = 0; i < headTokens; i++) {
int separatorIndex = rest.indexOf(SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalStateException("Can't parse parameter: " + parameterString);
}
tokens.add(rest.substring(0, separatorIndex));
rest = rest.substring(separatorIndex + 1);
}
tokens.add(rest);

return tokens;
}

public Object getSerializableValue(@Nullable Object value) {
if (value == null) {
return "";
Expand Down
Loading