MVC question


We have at our company now a very common, simple way to build our screens.
Of course the MVC pattern is implemented and the topology is something like that:

  • M: EJB based data access
  • C: servlet based controller classes (1 main servlet - N controller classes)
  • V: plain HTML + JS generated by own Java “HClasses” every time (the whole page is refreshed…)
    And we would like to enhance this operations so thats why i am interested in Vaadin.
    I like it very much but I am not sure its for us, please help me! :slight_smile:

As I see so far Vaadin is a bit of a monolith kind of system. I mean when you work in
Vaadin you start to create your application basicly as a screen and then write the
controller layer through creating the “Listeners” in the same class, etc. But we have a
lot of smaller screens called maintainer screens, lets say a 100 of them. So there is a
main servlet who delegates the controlling to the appropriate (actual) controller class.
Most of the screens just manage the simple CRUD operations and some of them the complex BL
but the thing is: they are very generic and similar to each other, so we have a generic
solution to render these screens so most of the time you dont have to deal with the “V”
layer at all. But now we dont have fancy components like in Vaadin and not even AJAX, etc.

My question is: if we would like to use Vaadin only as a extended, rich “page renderer engine”
can we do that? Without have to pass this kind of multiscreen controller structure to the “V” layer.

Thanks is advance!

I dont know, if I understand properly, what you are asking, but I think, that you have problem with understanding the difference between MVC Framework and component framework…

in MVC Framework, you have, as you have in you current project, some so called “Front controller” that deparses the request and decides, which controller will process the request…

in Component framework, the situation is the same, but completly different…the MVC of component framework is on different level of granularity, because every component (guestbook, enquiry, menu) has its own controller and you are putting these components together on one page (view), but you can for example build the tree in runtime (so the same page can be copletely different with every request, or you can easily integrete plugins (that is very problematic with MVC framework))…

for example in vaain, if i have grasped its idea, you have ussually one view for whole app, and you are changing the components inside it…you click on menu item, and the system changes only the part with content (via out-of-the box AJAX)…my sollusion for my app is to have some abstractPage (and impelmetantion for every view), from which I am inheriting common components (menu, header, footer), and exchanging these complete pages…this approach is simple combination of MVC and Component approach, because it woks almost like MVC, but i can simply use CSS for layout generation, and generate sobe plug-in components on-the-fly

So I think, that component framework does exactly, what you want, because you wold have some GenericPageGenerator, to which you wolud provide some info about the page, and it would generate for you the version of page you need…in fact, vaadin works only this way in opposite of JSF or Wicket, where you have to write markup, in vaadin you never write markup, because of the java => javascript translation…(and this is the problem for pages, tjhat need to be indexedm because there no way to achieve indexing of JS pages…)

The short answer: I think than in component framework you can do everything, what you can do in MVC approach, and you can do something more…(but you lose URL controll in vaadin…corect me, if I am wrong)

I hope that I have answered your question


Thanks Pavel!

I know what a component framework is and actually thats the point:
I thougth maybe I could use Vaadin “only” as a view renderer tool without
having to change our main concept of handling and controlling our screens
based on the fact that by us the screens are very simple in general because
they dont have any special events and logic at all (most of the cases).

or example in vaain, if i have grasped its idea, you have ussually one view for whole app
So lets say I have 100 screens in my app (there is a menu somewhere on the top with
10 modules and with 10 screens per module) how would you handle this in Vaadin?
How would you “activate” and display a screen and then change to a completely
another screen and when you’ve done going back to the first screen, etc? For example:

Screen #0: login, vaadin app init, etc…
→ selecting the “reservations” screen from the menu
Screen #1: a list screen of the recent reservations
→ pressing Button “Add”
Screen #2: an “add new reservation” screen (a form with empty fields)
→ next to the client input field pressing another Button “add new client…”
Screen #3: an “add new client” screen (a form again…)
→ down there would be a list whith the client’s addresses → press “add new address…” button
Screen #4: an “add new address” screen (a form again…)
→ and when everything is done going back from screen the screen till the #1

Currently we dont open any new windows for that kind of operations just
change the actual screen according to the appropriate actual function.
So how would you put the needed screen into your main vaadin application?
Every screen shoud be represented as a “Panel” and the “Front Controller Main Vaadin App”
should change its “mainContent” panel to the needed screen? And then how would you
communicate between the screens? For example: to write back the new clientId to the client
field on the form on Screen #2 after you added him to the system (and to the DB for eg).

Sorry if i am too foggy or trying to merge 2 kind of different patterns.
Just thinking how to create a new (vaadin based) MVC environment from an old one.

No one?

Another question:
The solutions in component handling provided for example by Spring or Seam namely
the Session, Conversation and Request Scope beans can be reasonable inside a Vaadin
application or because it is a typical component based environment, they are practically
unnecessary? (Except for some technical stuff like logging transaction handling, etc…)

here’s a few links for your questions - doing a view handler and login functionalities:

MVC Basics in Vaadin

Authenticating Vaadin-based applications

Changing a view can be done by changing a component in your window - which is usually a layout. You can have your hundred views as “public class myFineView extends CustomComponent {…”. You just then have a bunch of buttons or anything else that can have a clicklistnener attached to it(tree, accordion etc). When the clickEvent reaches the listener you do something like this:

public void buttonClick(ClickEvent event) {
  if(event.getButton()== myFineViewButton){
    if(myFineView == null){
      myFineView = new MyFineView();
    mainLayout.replaceComponent(currentComponentInView, myFineView);
  // And others similiar

This is one way to do it, hopefully it was something you were looking for. I guess there are other ways too.
As long as you have your logic as a selfcontained “module” you can just build views that gets information from your logic’s API. Only changes to the logic that I can come up to think of is possibly building containers for the views - as they are easy to use when you put in data to your view’s fields.

Thanks Jens!

The screen handling part is getting clearer now!

And what about the container part? I mean does a Vaadin application
in general need any container managed components at all?
Ok, I can imagine some technical Dependency Injection part
for example logging but do we need it for beans?

I saw that in Vaadin it is a bit problematic to solve the transaction handling for
example on request level automatically. Does someone have any experience on that?

(Using Hibernate with Vaadin)