PDA

View Full Version : Grid<BeanModel> selection bug



soma13
24 Nov 2011, 2:27 PM
Hi All,

I spent a lot of time with it and I think it is a bug. I have made a Grid<BeanModel> in a ContentPanel. After it shows I select a row and after it I click on an another row. When I do it the first selected row is not unselected but the new row will be selected too. And now, I have two selected row. And I have three selected row...

My java bean:
public class Advertisement implements java.io.Serializable
{
private Long id = null;
private String sessionId = null;
private String subject = null;
private String description = null;
...

/**
* id
*/
public Long getId()
{
return id;
}

public void setId(Long id)
{
this.id = id;
}

/**
* sessionId
*/
public String getSessionId()
{
return sessionId;
}

public void setSessionId(String sessionId)
{
this.sessionId = sessionId;
}
...
}

my model java file:
import com.extjs.gxt.ui.client.data.BeanModelMarker;
import com.extjs.gxt.ui.client.data.BeanModelMarker.BEAN;
import com.remal.marshall.shared.bean.Advertisement;

@BEAN(Advertisement.class)
public interface AdvertisementBeanModel extends BeanModelMarker
{
}

my entry poit class:
public class TestEP implements EntryPoint
{
@Override
public void onModuleLoad()
{
RootPanel rootPanel = RootPanel.get();
rootPanel.add( new MyGridPanel() );
}
}

my contentpanel files:
public class MyGridPanel extends ContentPanel
{
public MyGridPanel()
{
setLayout( new FitLayout() );
setSize(600, 600);

List<ColumnConfig> columnConfig = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("description");
column.setHeader("Description");
column.setWidth(200);

columnConfig.add(column);

ColumnModel cm = new ColumnModel(columnConfig);

MemoryProxy proxy = new MemoryProxy<List<Advertisement>>( Generator.getAdvertisements() );
BeanModelReader reader = new BeanModelReader();
BaseListLoader loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);

loader.load();

final Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoExpandColumn("description");
//grid.disableEvents(true);
//grid.disableTextSelection(true);
//grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

add(grid);
}
}


My screenshot is attached. When I click on the "row11" item then the selected rows are not unselect but the "row11" item will be selected too.

I think it is a bug. Or there is a wrong thing in my code. I do not know.

Could you check it?

regards, zappee

sven
25 Nov 2011, 1:29 AM
Can you please post a fully working testcase implementing EntryPoint for this? All the examples show a different behaviour.

soma13
28 Nov 2011, 1:58 PM
Hi sven,

I have made some new test cases nowadays. The results are the same :(
But now I know what is the difference between my well-working grid and the not working grid. In my test cases the grid1 uses BaseModel bean. The grid2 uses BeanModel bean. And the grid3 uses BeanModel too but the java bean is in an external commons jar. The grid3 selection is not working well. See the attached picture.

I do not understand what is the problem with java files in my external jar.
Do you have any idea how can I resolve this problem?

Thank you, zappee

29637

soma13
29 Nov 2011, 2:03 PM
Hi sven,

I have found what was the problem!

There is a equals method in my java bean. I made it for other reasons.

That's it:
@Override
public boolean equals(Object obj)
{
boolean result = false;

if (obj != null && obj.getClass() != getClass() && obj != this)
{
Advertisement advertisement = (Advertisement) obj;
if ( advertisement.getId() == getId() )
{
result = true;
}
}

return result;
}

When I comment this method, my grid selection is working well.
I do not know what is the problem with my equals method, but when I don't use it the grid selection is working well.

Could you tell me what is the relationship between equals method and grid selection?

thx

sven
29 Nov 2011, 11:04 PM
Is it possible that your IDs are always the same?

soma13
30 Nov 2011, 1:04 AM
Yes, it is.

In my test cases, the value of id field is always null.

sven
30 Nov 2011, 12:15 PM
Than you should fix that or remove the equals override and it will work correctly ;)

Colin Alworth
1 Dec 2011, 4:50 PM
Remember too that if you redefine equals in a java class, you should also redefine hashCode to be consistent with equals.