-
22 Jul 2010 5:24 AM #1
[FNR] Filters. Bug and inheritance problem.
[FNR] Filters. Bug and inheritance problem.
Hi.
I have found a bug in Date Filter (On same date comparison doesn't work as expected)
In file:
DateFilter.java:
Replace: if (afterItem.isChecked() && onMenu.getDate() != null) {
by: if (onItem.isChecked() && onMenu.getDate() != null) {
Moreover:
Is it possible to modify method validateModel:
public class DateFilter extends Filter {
....
@Override
public boolean validateModel(ModelData model) {
Date d = model.get(dataIndex);
..
}
...
}
by something like:
public class DateFilter extends Filter {
....
public Object getValue(ModelData model) {
return model.get(dataIndex);
}
@Override
public boolean validateModel(ModelData model) {
Date d = getValue();
..
}
...
}
My model doesn't contain Date but a Type witch can return a Date.
With this solution i can write a class witch extend DateFilter like:
public class MyOwnTypeFilter extends DateFilter {
public Object getValue(ModelData model) {
MyOwnType obj = (MyOwnType)model.get(dataIndex);
return (Date) obj.getMyDate();
}
}
Please modify all object witch inherit from Filter like this one.
Without this, we must duplicate lot of your code.
Thanx
-
22 Jul 2010 5:33 AM #2
Fixedi n SVN as of revision 2155.
Your suggestion is not a real bug, but we will take a look at it to add a helper method. But it wont be a public one as you suggested.
-
22 Jul 2010 5:38 AM #3
Thank you for your quick answer/fix.
Can you let me know when the "helper method" will be implemented?
-
19 Aug 2010 5:51 AM #4
I added the helper method in SVN at revision 2195
-
8 Mar 2012 5:13 AM #5
Hi Sven,
Does GXT 2.2.5 include those fix you are talking about?
I think I found a bug on the use of Filter, unless I m missing something.
If you add a DateFilter, then selecting a date for the "before" will check the menu before and apply the filter
If you come back on the filter, then only check the menu, it is throwing Nullpointer exception.
Looking at the code, I would understand that I missed the initialisation to set the initial value for the different calender view associated with each menu.
But using setValue on the DateFilter, requires a list of FilterConfig, doing this, will check (enable) every menu used by the DateFilter, therefore activating the filtering.
-
8 Mar 2012 5:46 AM #6
updateMenuState is called when onCheckChange is threshold
Inside:
beforeItem.setChecked(beforeMenu.getDate() != null && beforeMenu.getDate().after(afterMenu.getDate()), true);
if you never went on the date picker "afterMenu", the getDate return null
Same for beforeMenu
beforeItem.setChecked(beforeMenu.getDate() != null && beforeMenu.getDate().after(afterMenu.getDate()), true);
A nullpointer happend when check one item (before or after), and then check the another one.
-
8 Mar 2012 6:43 AM #7
Workaround:
The updateMenuState that create the nullpointer on After/Before checkMenuItem, because of the DateFilter native implementation, we cannot access the different menu objects, so we need to init first some reference used by the override of the method. We check null on DateMenu.getDate before doing the after method or before method.
Filter filter = new DateFilter(colName){
//Reference because native impl ref are private
CheckMenuItem myOnItem = null;
CheckMenuItem myAfterItem = null;
CheckMenuItem myBeforeItem = null;
DateMenu myAfterMenu = null;
DateMenu myBeforeMenu = null;
//Init method run once the first update to get reference setup
void initMenuItem()
{
if(myOnItem != null && myAfterItem != null && myBeforeItem != null)
return;
Menu menu = getMenu();
if(menu != null)
{
List<Component> comp = menu.getItems();
for (Component component : comp) {
if(component instanceof CheckMenuItem)
{
CheckMenuItem menuItem = (CheckMenuItem)component;
if(menuItem.getText().equals(getMessages().getOnText()))
myOnItem = menuItem;
else if(menuItem.getText().equals(getMessages().getAfterText()))
{
myAfterItem = menuItem;
myAfterMenu = (DateMenu) myAfterItem.getSubMenu();
}
else if(menuItem.getText().equals(getMessages().getBeforeText()))
{
myBeforeItem = menuItem;
myBeforeMenu = (DateMenu) myBeforeItem.getSubMenu();
}
}
}
}
}
//Override updateMenuState that cause nullpointer
protected void updateMenuState(Component item, boolean isChecked) {
//init inner ref
initMenuItem();
if (item == myOnItem) {
myOnItem.setChecked(isChecked, true);
if (isChecked) {
myBeforeItem.setChecked(false, true);
myAfterItem.setChecked(false, true);
}
} else if (item == myAfterItem) {
myAfterItem.setChecked(isChecked, true);
if (isChecked) {
//Date null is checked
myBeforeItem.setChecked(myBeforeMenu.getDate() != null && ((myAfterMenu.getDate() != null && myBeforeMenu.getDate().after(myAfterMenu.getDate())) || myAfterMenu.getDate() == null), true);
myOnItem.setChecked(false, true);
}
} else if (item == myBeforeItem) {
myBeforeItem.setChecked(isChecked, true);
if (isChecked) {
myOnItem.setChecked(false, true);
//Date null is checked
myAfterItem.setChecked(myAfterMenu.getDate() != null && ((myBeforeMenu.getDate() != null && myAfterMenu.getDate().before(myBeforeMenu.getDate())) || myBeforeMenu.getDate() == null), true);
}
}
}
};
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
[FNR] TimeField bug?
By is84092 in forum Ext GWT: Bugs (2.x)Replies: 1Last Post: 12 Apr 2010, 5:02 AM -
[2.??][DUP] Bug when PagingToolBar works with filters such as gridFilter
By yuandong1222 in forum Ext 2.x: BugsReplies: 1Last Post: 25 Nov 2008, 9:37 PM -
[SOLVED] DataView, ListStore and filters... Question and Bug
By mrdecav in forum Ext GWT: Help & Discussion (1.x)Replies: 2Last Post: 15 Sep 2008, 3:23 PM -
Inheritance Problem
By deltafoxtrot in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 15 May 2008, 7:49 AM -
Destroy a form in ext 1.1 / Inheritance problem
By Ronaldo in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 15 Aug 2007, 9:42 AM


Reply With Quote