[Patch 2.2.1] filterMatchMode with lazy datatable

UI Components for JSF
blemasle
Posts: 27
Joined: 11 Apr 2011, 09:48

30 Jun 2011, 11:34

Hi,

I may have an improvment request ( :D ) concerning the fact that the

Code: Select all

filterMatchMode
parameter could only be used by static datatable. This seems to me like a design flaw. I think you should add a new signature to the LazyDataModel load method, like this one e.g :

Code: Select all

public abstract List<T> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters, Map<String, FilterConstraint> filtersMatchMode);
So users can work with the desired mode :)

This improvment needs a new method in DataTable.java, which will be getFiltersConstraints(), which simply return all the column.getFilterConstraint() in one collection.

This seems easy to implement, and could be very usefull (I'm actually having some troubles using a filterOptions on a lazy datatable because of this). In fact, like other thing I discussed here, I think I'm will implement this myself for 2.2.1 and provide a patch. So if anybody is interested in that, stay tuned !

;)

EDIT : I think that use getFilterMatchMode could be better becaused of the fact that it's just using String instead of a specified type... Maybe some constants like STARTS_WITH_MATCH_MODE, ENDS_WITH_MATCH_MODE, CONTAINS_MATCH_MODE and EXACT_MATCH_MODE should be turned public so they can be used in controllers ?

EDIT 2 : Here is the patch to make this working to those who are interested ;) You obviously need to change all your implementation of LazyDataModel to match the new signature

Code: Select all

Index: src/main/java-templates/org/primefaces/component/column/ColumnTemplate.java
===================================================================
--- src/main/java-templates/org/primefaces/component/column/ColumnTemplate.java	(revision 4532)
+++ src/main/java-templates/org/primefaces/component/column/ColumnTemplate.java	(working copy)
@@ -17,10 +17,10 @@
     }
 
     private FilterConstraint filterConstraint = null;
-    private final static String STARTS_WITH_MATCH_MODE = "startsWith";
-    private final static String ENDS_WITH_MATCH_MODE = "endsWith";
-    private final static String CONTAINS_MATCH_MODE = "contains";
-    private final static String EXACT_MATCH_MODE = "exact";
+    public final static String STARTS_WITH_MATCH_MODE = "startsWith";
+    public final static String ENDS_WITH_MATCH_MODE = "endsWith";
+    public final static String CONTAINS_MATCH_MODE = "contains";
+    public final static String EXACT_MATCH_MODE = "exact";
 
     public FilterConstraint getFilterConstraint() {
         String filterMatchMode = getFilterMatchMode();
Index: src/main/java-templates/org/primefaces/component/datatable/DataTableTemplate.java
===================================================================
--- src/main/java-templates/org/primefaces/component/datatable/DataTableTemplate.java	(revision 4532)
+++ src/main/java-templates/org/primefaces/component/datatable/DataTableTemplate.java	(working copy)
@@ -335,6 +335,14 @@
         getStateHelper().put("filters", filters);
     }
 
+	public Map<String,String> getFiltersMatchMode() {
+        return (Map<String,String>) getStateHelper().eval("filtersMatchMode", new HashMap<String,String>());
+    }
+
+    public void setFiltersMatchMode(Map<String,String> filters) {
+        getStateHelper().put("filtersMatchMode", filters);
+    }
+	
     private List<Integer> selectedRowIndexes = new ArrayList<Integer>();
 
     public void addSelectedRowIndex(Integer rowIndex) {
Index: src/main/java/org/primefaces/component/datatable/DataHelper.java
===================================================================
--- src/main/java/org/primefaces/component/datatable/DataHelper.java	(revision 4532)
+++ src/main/java/org/primefaces/component/datatable/DataHelper.java	(working copy)
@@ -110,21 +110,28 @@
 
         if(table.isLazy()) {
             Map<String,String> filters = new HashMap<String, String>();
+            Map<String, String> filtersMatchMode = new HashMap<String, String>();
             Map<String,Column> filterMap = table.getFilterMap();
 
             for(String filterName : filterMap.keySet()) {
                 Column column = filterMap.get(filterName);
                 String filterValue = params.get(filterName).toLowerCase();
-
+                String filterMatchMode = column.getFilterMatchMode();
+                
                 if(!isValueBlank(filterValue)) {
                     String filterField = resolveField(column.getValueExpression("filterBy"));
                     
                     filters.put(filterField, filterValue);
+                    filtersMatchMode.put(filterField, filterMatchMode);
                 }
+                
             }
 
             table.setFilters(filters);
+            table.setFiltersMatchMode(filtersMatchMode);
 
+            //loading data so table.getRowCount() is up to date
+            table.loadLazyData();
             //Metadata for callback
             if(table.isPaginator()) {
                 RequestContext.getCurrentInstance().addCallbackParam("totalRecords", table.getRowCount());
Index: src/main/java/org/primefaces/model/LazyDataModel.java
===================================================================
--- src/main/java/org/primefaces/model/LazyDataModel.java	(revision 4532)
+++ src/main/java/org/primefaces/model/LazyDataModel.java	(working copy)
@@ -80,5 +80,5 @@
         this.rowCount = rowCount;
     }
 
-    public abstract List<T> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters);
+    public abstract List<T> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String,String> filters, Map<String, String> filtersMatchMode);
 }
\ No newline at end of file
Last edited by blemasle on 30 Jun 2011, 14:13, edited 3 times in total.
Primefaces 2.2.1
Mojarra 2.1.1
Tomcat 7.0.11

blemasle
Posts: 27
Joined: 11 Apr 2011, 09:48

30 Jun 2011, 12:14

Patch is working great and available at the end of first post ;)
Primefaces 2.2.1
Mojarra 2.1.1
Tomcat 7.0.11

blemasle
Posts: 27
Joined: 11 Apr 2011, 09:48

05 Aug 2011, 15:55

I would really like to see some PrimeFaces developers answering this.

This is CLEARLY a design flaw in the LazyDataModel conception, so filterMathMode is useless with LazyDataTable...
This is not the first improvment I suggest here, and while I don't claim a medal or a special distinction, I would at least expect an answer from PrimeFaces team ;)
Primefaces 2.2.1
Mojarra 2.1.1
Tomcat 7.0.11

perissf
Posts: 15
Joined: 13 Nov 2010, 12:50

28 Dec 2011, 16:19

blemasle, I agree with you: I think that this feature should be implemented

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 Dec 2011, 18:13

blemasle wrote:I would really like to see some PrimeFaces developers answering this.

This is CLEARLY a design flaw in the LazyDataModel conception, so filterMathMode is useless with LazyDataTable...
This is not the first improvment I suggest here, and while I don't claim a medal or a special distinction, I would at least expect an answer from PrimeFaces team ;)
Thanks for creating this new topic. maybe you can add this to issue tracker, titled as, NEW FEATURE REQUEST: LazyDataModel filterMatchMode... or something similar, but honestly, you may want to make the patch for PrimeFaces versions 3.0..., because Optimus Prime is informing everyone that version 2.x is no longer supported. You may want to try this patch with Primefaces version 3.0, and label your NEW FEATURE REQUEST, accordingly, in issue tracker.

I'm going to bookmark this topic of yours, because I have so many LazyDataModel instances in my JSF/Primefaces web app, and would love to use filterBy, but had to come up with my own solution, and do the filtering in DAO via dynamic SQL SELECT, and that's working fine for me.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

perissf
Posts: 15
Joined: 13 Nov 2010, 12:50

28 Dec 2011, 21:33

I have submitted the issue with ID 3198.

pino
Posts: 10
Joined: 21 Jul 2012, 15:57

28 Jul 2012, 11:53

I voted +1 for the issue at http://code.google.com/p/primefaces/iss ... il?id=3198

regards
Rommel Pino
http://soadev.blogspot.com

Primefaces 3.4.2
Mojarra 2.1.6
GlassFish OSE 3.1.2.2
Netbeans 7.2.1
Firefox 17.0

André G.
Posts: 31
Joined: 20 Dec 2011, 14:05

03 Sep 2012, 15:13

Old, but still an issue in 3.3.1. Gave it a star as well.
PrimeFaces 6.0.7 with Mojarra 2.2.14 on Tomcat 7.72.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

03 Sep 2012, 15:25

Since user is responsible for filtering, why do you exactly need the filterMatchMode info? Filter the way you like it, you already have the field to filter.

This is the main reason why we are not very excited about this, if you have another idea, please try to convince us :) Maybe we miss something.


e.g.

Code: Select all

if field == 'year'
  filter with starts with
else if field == 'model'
  filter with contains
What is the main advantage if PF passes you the match mode from column?

skotinin
Posts: 1
Joined: 18 Sep 2012, 11:09

19 Sep 2012, 08:16

Hi!
optimus.prime wrote: What is the main advantage if PF passes you the match mode from column?
IMHO "match mode" would be set into the .xhtml file. Otherwise, it will have to remember to change the filter rules in the bean.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests