Grid: comparision between two bean containers?

Hi,

I have a use case where I need to compare between two beans container: one is some example bean container, and another is from the existing database. And I need to show redundant bean items in colored format.

Is it possible to do such using Vaadin Grid?

There is no simple way to do this, but the others should correct me if I am wrong.

I assume that your goal is to somehow highlight or indicate the items on the rows that are included in both containers (or datasets). There are number of possible ways to do that. Which fits your case is highly dependent on your application.

There is containsId() method in BeanItemContainer, which can be used to check whether container contains certain item. So it is possible to iterate thru the container and do things based on that.

By using Grid.rowReference and Grid.rowStyleGenerator, it is possible to change the stylename of the rows to show e.g. different color, which gives you the highlight effect. You need to configure that stylename in CSS of your theme. This can lead to tricky solution. I do not know how often you are updateing the “example bean container”.

It could be also an elegant solution to add one column to the grid with boolean value. In that case you could use converter and HTML renderer combination in that property to show a flag icon or something. This means that you need to update the boolean value by iterating your BeanItemContainer and check whether itemId’s are contained with the other container. This is somewhat easier than the first proposal, and could be more usable if you update the containers often.

Hey…

Thanks for your suggestions. I’ll have to experiment some of your ideas.