"
I am forced to implement the business logic in Container-Item fashion,It’s very mysterious,complex and ugly
"
Not at all. I fear the issue is indeed the fact you don’t understand how Container works rather than in the design of the data binding. I don’t say the latter cannot be improved, but it works.
I just made a prototype with Vaadin. I implemented the business logic (data model) in packages totally oblivious of the application using it. I can easily go back to Swing, or use JavaFX to exploit this data, if I want.
I made two classes to handle the data model on the Vaadin application side: a ReportContainer, to hold a Table’s data, implementing just AbstractContainer (I could have used AbstractInMemoryContainer but I prefer to do myself the stuff it does, as filtering, for example, is handled on the business logic side) and Container.Ordered (because otherwise Table with wrap the container to have Ordered data). On second though, I don’t use Filterable or Sortable, again, doing that on the other side.
I implemented just the some 13 required methods (plus some UnsupportedOperationException because my data is read-only). You have to add 8 more if you modify the data. That’s for the “complex” side.
I also have a ReportRow implementing Item, 2 methods and 2 unsupported ones.
Again, no business logic here, only accessing the face of the API of my BL designed to expose data.
Mysterious? A bit, I admit. I had to implement a number of methods with little idea of how they are used… Stuff like getItemProperty / getItemPropertyIds for Item (the latter is never called in my app.), containsId, getContainerPropertyIds or getContainerProperty for Container.
I made mock-up methods, added System.out.println() to see what parameters we get and when they are called, then I had a better understanding of the Table mechanism.
Moreover, looking at existing Container implementations, both in the Vaadin sources and from the Add-on Directory, helps a lot in understanding how this works.
The documentation can be improved (eg. in Table.setPageLength(), what is a page length? What is the unit (I found it is expressed in rows, but it is better to say it so)), but it is rather good, overall.
I found out the data binding logic to be quite easy to get and to use. Now, I am a Swing programmer, and this logic isn’t far from Swing’s logic, so perhaps it helped.
"
I am not sure when and how many times each container’s method will be executed
"
The println (or any log system you can have) method is useful to have real data on this kind of question…
"
for example:container has a method getItemIds(),it will return all record id,in huge data scene,this will be horrible performce killer.
"
I made a report with some 10,000 rows. No performance problem here. That’s a list of 10,000 ids (small objects) to return, it isn’t that big in an industrial Java application. Even a million of rows is still not a problem. One trick is to build the list once, and cache it. So on the next calls, you just serve this list, if it hadn’t changed.
Don’t fear performance issues, measure them! See where is the bottleneck (if you have any) with a profiler (like JVisualVM) and address the specific, real issue, not your fears.
"
we live in web. when user press F5 ,it means he want to get lastest data.
"
I don’t know if F5 works well in a Vaadin application (can be problematic if you still have ?restartApplication in the URL…) but nothing prevents you to bind another key to mean “refresh displayed data”, and to update the container or just call fireItemSetChange() to update the view.
"
(re)populate logic will be implemented,application developer can use his favorite technique to get data ,like Spring-JDBC,hibernate,cache… etc,not limited to implement container-related interface
"
To my knowledge, this kind of container already exists…
Maybe I don’t fully understand your proposal, but it looks like what you request can be already done with the existing code.
Maybe your message is a sign we need a step-by-step tutorial on how to build a custom container (another one, with a different angle, if
it already exists
).