Vaadin and Spring MVC Integration

后端 未结 6 1455
面向向阳花
面向向阳花 2021-01-31 17:59

I\'m thinking about the possibility of using Spring MVC with Vaadin Framework. Are there any documented ways of making them play nicely together ? Also is it a good idea to use

6条回答
  •  伪装坚强ぢ
    2021-01-31 18:55

    org.springframework.web.servlet.mvc.Controller's handleRequest takes a HttpServletRequest and HttpServletResponse as parameters. From these, you cannot process the URI fragment. As such, the controller is not suited for controlling requests based on URI fragment.

    In my application, I implemented very similar concept to Spring controller. My application still has a notion of "views" and "model". Each view is implemented in a separate class and is displayed in a central block of the page. I wanted to centralize logic of the URL processing to that class, so I created a class AbstractControllerEntry:

    public static abstract class AbstractControllerEntry {
        public abstract boolean matches(String fragment);
        public abstract void open(MainWindow window, String fragment);
    }
    

    with several convenience subclasses such as ConstantEntry, PrefixEntry and RegexEntry.

    Each view class has a static method, that returns AbstractControllerEntry. Collection of all entries is kept in a static array inside of MyController class (not a Spring MVC controller). Upon fragment change (see UriFragmentUtility), I iterate all entries, and for first, which matches, I will call open. Any other logic, such as finding the model object, is inside of the view class, in the AbstractControllerEntry implmentation.

    Additionaly, there's another static method to generate the URI fragment in the view class, so that each reference to a view is a real reference to a class, this is a solution to broken links. And each view has instance method to get a fragment for current view, which is checked to match a controller entry to increase robustness.

提交回复
热议问题