bgould / jmesa

Automatically exported from code.google.com/p/jmesa
0 stars 0 forks source link

Search using 2 dates #257

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 ;)

Original issue reported on code.google.com by andyned...@gmail.com on 7 Apr 2010 at 12:22

GoogleCodeExporter commented 9 years ago
Searching on two dates would work if you plug in a custom filter matcher. 

http://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.

Original comment by jeff.johnston.mn@gmail.com on 8 Apr 2010 at 1:51

GoogleCodeExporter commented 9 years ago
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;
      }
  } 
}

Original comment by andyned...@gmail.com on 9 Apr 2010 at 10:41

GoogleCodeExporter commented 9 years ago
If you want to modify that behavior you could plug in your own row filter 
functionality.

http://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.

Original comment by jeff.johnston.mn@gmail.com on 9 Apr 2010 at 7:28

GoogleCodeExporter commented 9 years ago
There is now a getPredicate() method on SimpleRowFilter. It is checked into the 
trunk and will go out with the 3.0.4 release.

Original comment by jeff.johnston.mn@gmail.com on 10 Mar 2011 at 9:40