简体   繁体   English

Vaadin和Spring MVC集成

[英]Vaadin and Spring MVC Integration

I'm thinking about the possibility of using Spring MVC with Vaadin Framework. 我正在考虑使用Spring MVC和Vaadin Framework的可能性。 Are there any documented ways of making them play nicely together ? 有没有任何记录的方法可以让它们很好地融合在一起? Also is it a good idea to use them together ? 同时使用它们也是个好主意吗? relating to performance; 与表现有关; I'm going to run the app on a dedicated server. 我将在专用服务器上运行该应用程序。

To make my question a bit more clear, how can i return a modelandview from a Spring MVC Controller that wll render using Vaadin and can access all the model data. 为了使我的问题更清楚,我如何从Spring MVC Controller返回一个modelandview,它将使用Vaadin呈现并可以访问所有模型数据。

Spring support for Vaadin is quite new, but there has recently been a lot of talk about it on the forum and some have tested it. Spring对Vaadin的支持是相当新的,但最近在论坛上有很多关于它的讨论,有些人已经对它进行了测试。 Seems to work. 似乎工作。 There is an article on the Vaadin wiki about it, and some threads on the forum talking about Vaadin + Spring integration: Vaadin维基上有一篇关于它的文章,论坛上的一些话题谈论Vaadin + Spring集成:

Wiki: Spring Integration Wiki:Spring Integration
Forum: can it mill toolkit be integrated with spring application 论坛:它可以将工具包与spring应用程序集成
Forum: Spring integration problem 论坛:Spring集成问题
Forum: Working with Spring 论坛:与Spring合作
Forum: Spring Integration 论坛:Spring Integration

Not sure if it is a prudent choice to integrate vaadin with Spring MVC. 不确定将vaadin与Spring MVC集成是否是一个谨慎的选择。 Its a waste. 这是浪费。 MVC is meant for typical page based web apps where as vaadin is more view state based like a desktop app. MVC适用于典型的基于页面的Web应用程序,其中vaadin更像是基于桌面应用程序的视图状态。 I would typically do a meet in the middle and have my business tier and data access layer in spring and use Vaadin as is. 我通常会在中间进行会面并在春季使用我的业务层和数据访问层并按原样使用Vaadin。

在Vaadin论坛上查看我的AutowiringApplicationServlet解决方案的这个主题 ,包括一个示例WAR应用程序。

agreed with dhrbo. 同意dhrbo。

its not wise to use spring mvc, more so with webflow with vaadin. 使用spring mvc是不明智的,更多的是使用带有vaadin的webflow。 vaadin is another web-app framework. vaadin是另一个Web应用程序框架。

if you want the idea of "spring mvc" in your vaadin project, integrate it with spring-core, beans and context. 如果你想在你的vaadin项目中使用“spring mvc”的想法,那么将它与spring-core,beans和context集成在一起。 that way you can get a clear separation between controllers, ui (vaadin), and models (integrate with hibernate / orms) 这样你就可以清楚地分离控制器,ui(vaadin)和模型(与hibernate / orms集成)

Here's an article on integrating Spring service layer with Vaadin. 这是一篇关于将Spring服务层与Vaadin集成的文章。 It does not directly relate to Spring MVC that the original question was about, but it can still be a pointer for other readers researching Vaadin Spring integration. 它与原始问题所涉及的Spring MVC没有直接关系,但它仍然可以成为研究Vaadin Spring集成的其他读者的指针。

http://psponcoding.blogspot.com/2011/03/vaadin-spring-integration.html http://psponcoding.blogspot.com/2011/03/vaadin-spring-integration.html

org.springframework.web.servlet.mvc.Controller 's handleRequest takes a HttpServletRequest and HttpServletResponse as parameters. org.springframework.web.servlet.mvc.Controller的handleRequest将HttpServletRequestHttpServletResponse作为参数。 From these, you cannot process the URI fragment. 从这些中,您无法处理URI片段。 As such, the controller is not suited for controlling requests based on URI fragment. 因此,控制器不适合于基于URI片段控制请求。

In my application, I implemented very similar concept to Spring controller. 在我的应用程序中,我实现了与Spring控制器非常相似的概念。 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 : 我想将URL处理的逻辑集中到该类,所以我创建了一个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 . 有几个方便的子类,如ConstantEntryPrefixEntryRegexEntry

Each view class has a static method, that returns AbstractControllerEntry . 每个视图类都有一个静态方法,它返回AbstractControllerEntry Collection of all entries is kept in a static array inside of MyController class (not a Spring MVC controller). 所有条目的集合都保存在MyController类(不是Spring MVC控制器)内的静态数组中。 Upon fragment change (see UriFragmentUtility ), I iterate all entries, and for first, which matches, I will call open. 片段更改后(参见UriFragmentUtility ),我迭代所有条目,首先,哪些匹配,我将调用open。 Any other logic, such as finding the model object, is inside of the view class, in the AbstractControllerEntry implmentation. 任何其他逻辑(例如查找模型对象)都位于视图类的AbstractControllerEntry

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. 另外,还有另一种静态方法在视图类中生成URI片段,因此每个对视图的引用都是对类的真实引用,这是对断​​开链接的解决方案。 And each view has instance method to get a fragment for current view, which is checked to match a controller entry to increase robustness. 并且每个视图都有实例方法来获取当前视图的片段,检查该片段以匹配控制器条目以增加稳健性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM