Issue 257: Search using 2 dates
Status:  Fixed
Owner: ----
Closed:  Mar 2011
Reported by andyned...@gmail.com, Apr 7, 2010
Hello to everybody!!

I have 2 "Date columns" (Column "FROM" and Column "TO"), and I would like
to search all the information between that date. How could I do it??


Thanks so much for your attention ;)

Apr 7, 2010
Project Member #1 jeff.johnston.mn@gmail.com
Searching on two dates would work if you plug in a custom filter matcher. 

https://code.google.com/p/jmesa/wiki/FilterMatcher

It might be more user friendly though if you put the from and to columns into one
column and then put a matcher on that. If you have two columns then you would have to
have one column say "> from"  and the other to say "< to". Something like that. With
one column the filter could be "from - to". All you need to do from the bean
standpoint is add a method on your bean (item) that returns the formatted string of
both columns.

What is not easily done is getting the row to span two columns in the header. A JMesa
table assumes the layout is in rows and columns with no spans. 

Hope that helps...let me know if you need more.

P.S. If you do not mind a post like this is better suited for the forums...just makes
it easier for other developers to follow.

Status: Accepted
Apr 9, 2010
#2 andyned...@gmail.com
I've follow your indications, and finally I created a FilterMacher class:
tablefacade.addFilterMatcher(new MatcherKey(Date.class, "from"), new FilterNewsFrom());
tablefacade.addFilterMatcher(new MatcherKey(Date.class, "to"), new FilterNewsTo());

I've a problem with the field "TO". All my news without TO (field "To"=null)never
don't expire and if I search with a date in that field, JMesa don't show me the news
with To=null. Only search if "To" get a date to compare.

-------------------

public class FilterNewsTo implements FilterMatcher {
	
  @Override
  public boolean evaluate(Object itemValue, String filterValue) {
    Log logger =
CmsLog.getLog("es.sopde.panelmunicipios.templates.plantillaGestorNoticias.jsp");
		
    Date dateTo = (Date)itemValue;
    try{
      SimpleDateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");
      Date dateSearch = sdf.parse(filterValue);
      if (dateTo==null || dateTo.after(dateSearch))
        return true;
      else
        return false;
      }catch (ParseException e){
        logger.error("******* ParseException:" + e.getMessage());
        System.out.println("**ERROR: No se ha podido transformar el filtro de
búsqueda de la \"Fecha Hasta\" en un tipo Date. -- " + e.getMessage());
        return false;
      }catch (Exception e){
        logger.error("******* ParseException:" + e.getMessage());
        System.out.println("**ERROR: Fallo al filtrar el campo \"Fecha Hasta\". -- "
+ e.getMessage());
        return false;
      }
  }	
}
Apr 9, 2010
Project Member #3 jeff.johnston.mn@gmail.com
If you want to modify that behavior you could plug in your own row filter functionality.

https://code.google.com/p/jmesa/wiki/CustomSimpleRowFilter

Except what you will need to do is override the filterItems() method and plug in a
custom filter predicate. Just take the existing predicate and tweak it out how you
need to.

You know what I should do as well is make it so that you can just extend the
SimpleRowFilter and plug in your predicate. Even though there is not much to the
filterItems() method it would still be much more flexible.


Mar 10, 2011
Project Member #4 jeff.johnston.mn@gmail.com
There is now a getPredicate() method on SimpleRowFilter. It is checked into the trunk and will go out with the 3.0.4 release.
Status: Fixed