Container type available?


lets say I have a bean (POJO) named Row

public class Row { private int value1; private int value2; private int sum; // value1 + value2 } Also I have a bean (POJO) names Rows with contains some Row objects

public class Rows { // class contains some logic regarding all containing row objects.
private List<Row> rows = new ArrayList<Row>();
public int getSumOfAllRows()
   return traverseAllRowsAndSumUpSum()

Now I have a widget, let’s say a table, where I want to connect the model (beans) to.
The usual way would be something like:

table.setContainerDataSource(beanItemContainerContainingAllRowObjectsAddedWithMethodAddItem); What I want is not to add a bunch of Row object to the BeanItemContainer but to use my Rows object (which contains some logic) as a container. Is there any predefined way by using a certain container type or do I have to implement it by my own? Any other suggestions how to implement that?

Thanks in advance!

No, there isn’t a version of BeanItemContainer that would take in an object with a list of objects within it, instead of just taking the list.

You could extend BeanItemContainer (or IndexedContainer) to do that, but I really don’t see the point in it without additional information. The table could still not react on your custom logic because it doesn’t know about it. Maybe you could tell me a bit more about what your goal is and someone could try to suggest some alternative way to do it?

Quick answer, thanks!

The point is that I implemented some POJOs (and tests) before creating the GUI. As said, since there is logic regarding all rows (to be displayed under the table) I encapsulated the list and the logic (supposed to be clean code).

That’s what I have now, before start creating the GUI. What I don’t want is to change the POJOs / beans / domainObjects/ whatEverYouWannaCallIt just to be able to create a GUI. I’d like to use these objects as they are, because I think it makes sence to encapsulate logic…

If changing the existing classes isn’t an option, then the only thing you can do is to create your own container (preferrably by extending an existing one). In your case it might be easiest to just use an IndexedContainer, since you’ll have to build it yourself anyway.

Or do it in a Model-View-Presenter kind of way, which adds to the clean code aswell. Have a presenter with all the view logic and a view that is really dumbed down. The view asks for specific data from the presenter. On all button presses or item selections the view just informs the presenter that “user selected item X in table” instead of updating anything directly.

Then in your presenter you have a reference to the POJO you mentioned. When view needs data, the presenter fetches the rows from the POJO and sends them forward to the view. When the user does an action that requires usage of the logic in the POJO, the view delegates the info to the presenter and the presenter delegates it to the POJO. The presenter gets back updated info and then updates the view accordingly.

How would that sound?

Hi and thanks again.

Indeed that sounds good, that’s why I have MVP already implemented :).
Just prefering to move the logic into the domain objects…

Your mentioned solution does require a lot of event dispatching, which works, but is a lot of code. My question: is it possible to bind a complex model with nested beans (datasource is a BeanItemContainer) to a complex view (which is a table, where one row [having several widgets]
represents one bean)?

What I get until now is one table row per data source item, but in Vaadin it seems to be really hard to bind nested beans with inner components of a table item…?

Unfortunately I still have to use Vaadin 6.x.

PS: Writing an own container is too much work I guess, thats why I am using BeamItemContainer as data source…