Repository: primefaces/primefaces (java)

Issue:
Datatable: Default filter feature broken in showcase with PF15
### Describe the bug

While doing some manual testing for the JS refactor PR, I noticed the default filter feature from the showcase is broken and throws an exception.

### Reproducer

* Fetch the lastest state of the master branch (I used ccfd6d682d8041fd01a7af50c0fdaadde91e8d10), start the showcase and goto the data table filter feature page: http://localhost:8081/showcase/ui/data/datatable/filter.xhtml
* Scroll down to `Default Filter`
* Attempt to use any of the filter. E.g. I clicked in the filter at the top of the `Country` column and entered `Spain`

This results in a generic error page with the following stacktrace:

```
Dec 08, 2024 2:03:26 PM org.primefaces.application.exceptionhandler.PrimeExceptionHandler logException
SEVERE: Filter 'NEW' of type 'java.lang.String' cannot be casted to value type 'NEGOTIATION'. Forgot to add a converter?
java.lang.IllegalArgumentException: Filter 'NEW' of type 'java.lang.String' cannot be casted to value type 'NEGOTIATION'. Forgot to add a converter?
	at org.primefaces.model.filter.ComparableFilterConstraint.assertAssignable(ComparableFilterConstraint.java:57)
	at org.primefaces.model.filter.EqualsFilterConstraint.isMatching(EqualsFilterConstraint.java:44)
	at org.primefaces.component.datatable.feature.FilterFeature.lambda$filter$0(FilterFeature.java:153)
	at org.primefaces.component.api.ColumnAware.forEachColumn(ColumnAware.java:102)
	at org.primefaces.component.api.ColumnAware.forEachColumn(ColumnAware.java:55)
	at org.primefaces.component.api.ColumnAware.forEachColumn(ColumnAware.java:51)
	at org.primefaces.component.datatable.feature.FilterFeature.filter(FilterFeature.java:132)
	at org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:94)
	at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:93)
	at jakarta.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:586)
	at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1442)
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:624)
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:158)
	at jakarta.faces.component.visit.VisitContextWrapper.invokeVisitCallback(VisitContextWrapper.java:92)
	at org.primefaces.component.api.PrimeUIData$VisitContextImpl.invokeVisitCallback(PrimeUIData.java:508)
	at org.primefaces.component.patch.UIDataPatch.visitTree(UIDataPatch.java:877)
	at org.primefaces.component.api.PrimeUIData.visitTree(PrimeUIData.java:292)
	at jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
	at jakarta.faces.component.UIForm.visitTree(UIForm.java:344)
	at jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
	at jakarta.faces.component.UIComponent.visitTree(UIComponent.java:1278)
	at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:394)
	at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:312)
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:61)
	at jakarta.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1092)
	at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1435)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:422)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:160)
	at jakarta.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:125)
	at jakarta.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:125)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:93)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:150)
	at jakarta.faces.lifecycle.LifecycleWrapper.render(LifecycleWrapper.java:91)
	at jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:692)
	at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:449)
	at org.eclipse.jetty.ee10.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1379)
	at org.eclipse.jetty.ee10.servlet.ServletHolder.handle(ServletHolder.java:736)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1614)
	at org.primefaces.webapp.filter.NoCacheFilter.doFilter(NoCacheFilter.java:50)
	at org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)
	at org.primefaces.webapp.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:53)
	at org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:208)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)
	at org.eclipse.jetty.ee10.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:195)
	at org.eclipse.jetty.ee10.servlet.FilterHolder.doFilter(FilterHolder.java:205)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1586)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$MappedServlet.handle(ServletHandler.java:1547)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.dispatch(ServletChannel.java:819)
	at org.eclipse.jetty.ee10.servlet.ServletChannel.handle(ServletChannel.java:436)
	at org.eclipse.jetty.ee10.servlet.ServletHandler.handle(ServletHandler.java:464)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:575)
	at org.eclipse.jetty.ee10.servlet.SessionHandler.handle(SessionHandler.java:717)
	at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:151)
	at org.eclipse.jetty.server.Server.handle(Server.java:182)
	at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:662)
	at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:418)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
	at java.base/java.lang.Thread.run(Thread.java:840)
```

### Expected behavior

No error page should show up, the filter should be applied to the database.  Not sure if PF or the showcase needs to be updated. It works in the [current PF 14 showcase](https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml)

### PrimeFaces edition

None

### PrimeFaces version

ccfd6d682d8041fd01a7af50c0fdaadde91e8d10

### Theme

_No response_

### JSF implementation

All

### JSF version

2.3.21

### Java version

17

### Browser(s)

_No response_

Pull request:
Fix #13018: 14.0.9 EqualsFilterConstraint handle enum/string
Fix #13018: 14.0.9 EqualsFilterConstraint handle enum/string

Patch:
diff --git a/primefaces/src/main/java/org/primefaces/model/filter/EqualsFilterConstraint.java b/primefaces/src/main/java/org/primefaces/model/filter/EqualsFilterConstraint.java
index 8d0bc5fb8a..0e450f62f3 100644
--- a/primefaces/src/main/java/org/primefaces/model/filter/EqualsFilterConstraint.java
+++ b/primefaces/src/main/java/org/primefaces/model/filter/EqualsFilterConstraint.java
@@ -37,6 +37,10 @@ public class EqualsFilterConstraint implements FilterConstraint {
         if (value == null || filter == null) {
             return false;
         }
+        // Handle enum values by comparing their string representations
+        if (value.getClass().isEnum() || filter.getClass().isEnum()) {
+            return value.toString().equals(filter.toString());
+        }
         // If Comparable, prefer compareTo to handle BigDecimal, etc.
         if (value instanceof Comparable) {
             ComparableFilterConstraint.assertAssignable(filter, value);


Test patch:
diff --git a/primefaces/src/test/java/org/primefaces/model/filter/EqualsFilterConstraintTest.java b/primefaces/src/test/java/org/primefaces/model/filter/EqualsFilterConstraintTest.java
new file mode 100644
index 0000000000..8c0bcf2925
--- /dev/null
+++ b/primefaces/src/test/java/org/primefaces/model/filter/EqualsFilterConstraintTest.java
@@ -0,0 +1,134 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2009-2024 PrimeTek Informatics
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.primefaces.model.filter;
+
+import java.math.BigDecimal;
+import java.util.Objects;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class EqualsFilterConstraintTest {
+    private EqualsFilterConstraint constraint;
+
+    @BeforeEach
+    void setup() {
+        constraint = new EqualsFilterConstraint();
+    }
+
+    @Test
+    void testCompareToEquals_Equal() {
+        assertTrue(constraint.compareToEquals(BigDecimal.ONE, BigDecimal.ONE));
+    }
+
+    @Test
+    void testCompareToEquals_NotEqual() {
+        assertFalse(constraint.compareToEquals(BigDecimal.ONE, BigDecimal.TEN));
+    }
+
+    @Test
+    void testCompareToEquals_BigDecimalPlaces() {
+        assertTrue(constraint.compareToEquals(new BigDecimal("1.0"), new BigDecimal("1.0000")));
+    }
+
+    @Test
+    void testIsMatching_SameReference() {
+        Object value = "test";
+        assertTrue(constraint.isMatching(null, value, value, null));
+    }
+
+    @Test
+    void testIsMatching_NullValue() {
+        assertFalse(constraint.isMatching(null, null, "test", null));
+    }
+
+    @Test
+    void testIsMatching_NullFilter() {
+        assertFalse(constraint.isMatching(null, "test", null, null));
+    }
+
+    @Test
+    void testIsMatching_EnumValues() {
+        assertTrue(constraint.isMatching(null, TestEnum.A, TestEnum.A, null));
+        assertFalse(constraint.isMatching(null, TestEnum.A, TestEnum.B, null));
+    }
+
+    @Test
+    void testIsMatching_EnumValuesAsString() {
+        assertTrue(constraint.isMatching(null, TestEnum.A, "A", null));
+        assertFalse(constraint.isMatching(null, TestEnum.A, "B", null));
+    }
+
+    @Test
+    void testIsMatching_ComparableNumbers() {
+        assertTrue(constraint.isMatching(null, BigDecimal.ONE, BigDecimal.ONE, null));
+        assertFalse(constraint.isMatching(null, BigDecimal.ONE, BigDecimal.TEN, null));
+    }
+
+    @Test
+    void testIsMatching_NonComparableObjects() {
+        Object obj1 = new TestObject("test");
+        Object obj2 = new TestObject("test");
+        Object obj3 = new TestObject("different");
+
+        assertTrue(constraint.isMatching(null, obj1, obj2, null));
+        assertFalse(constraint.isMatching(null, obj1, obj3, null));
+    }
+
+    @Test
+    void testIsMatching_InvalidComparison() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            constraint.isMatching(null, BigDecimal.ONE, "1", null);
+        });
+    }
+
+    private enum TestEnum {
+        A, B
+    }
+
+    private static class TestObject {
+        private final String value;
+
+        TestObject(String value) {
+            this.value = value;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+            TestObject that = (TestObject) o;
+            return Objects.equals(value, that.value);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(value);
+        }
+    }
+}