2013-10-04 135 views
2

將Spring和vaadin集成很好嗎?我正在尋找使用vaadin視圖層和春天爲我的服務。到目前爲止,我無法找到任何整合解決方案。像管理解決方案或ERP這樣的生產應用程序是一個好主意嗎?集成彈簧和vaadin

  • 什麼可能是應用程序的設計?
  • 如何保持應用程序層之間清晰的分離?
  • Vaadin與彈簧安全系統集成的問題?
  • 如何管理春豆的範圍?

也有人可以分享春季MVC這種集成的優點和缺點。

回答

0

你根本不需要任何特殊的vaadin插件。對於要與彈簧集成的每個組件,只需使用aspectj和@Configurable註釋以及@Autowired。就像這樣:

@Configurable(preConstruction = true) 
public class LoginUserPasswdDialog extends LoginDialogBase { 
static final Logger log = Logger.getLogger(LoginUserPasswdDialog.class); 

    @Autowired 
    private AppConfig config; 

    @Autowired 
    UserFactory userFactory; 

    StringBuffer name; 
    LoggedAction action; 

    protected Window parent = null; 
    protected Button ok; 
    protected Label l; 
    protected TextField nameText; 
    protected PasswordField password; 
    protected CheckBox saveUserPass; 

    protected final Window w = new Window(""); 

    @SuppressWarnings("serial") 
    public void create(AbstractComponent component) throws Exception { 
     parent = component.getWindow(); 

     VerticalLayout v = new VerticalLayout(); 
     v.setSizeFull(); 
     v.setSpacing(true); 

     l = new Label(
       _.getString("LoginUserPasswdDialog.0"), Label.CONTENT_XHTML); //$NON-NLS-1$ 
     l.setSizeFull(); 
     l.addStyleName("centeredLabel"); 
     v.addComponent(l); 

     HorizontalLayout h = new HorizontalLayout(); 
     h.setMargin(true); 
     h.setSpacing(true); 

     nameText = new TextField(); 
     nameText.setWidth("100%"); 
     v.addComponent(nameText); 
     nameText.focus(); 

     password = new PasswordField(); 
     password.setWidth("100%"); 
     v.addComponent(password); 

     saveUserPass = new CheckBox(_.getString("LoginUserPasswdDialog.1")); //$NON-NLS-1$ 
     v.addComponent(saveUserPass); 
     v.setComponentAlignment(saveUserPass, Alignment.MIDDLE_RIGHT); 

     ok = new Button(_.getString("LoginUserPasswdDialog.2")); //$NON-NLS-1$ 
     ok.setWidth("100px"); 
     ok.setClickShortcut(KeyCode.ENTER); 

     h.addComponent(ok); 
     h.setComponentAlignment(ok, Alignment.MIDDLE_CENTER); 

     v.addComponent(h); 
     v.setComponentAlignment(h, Alignment.MIDDLE_CENTER); 

     Cookie nameCookie = CookieUtils.getCookie("username"); 
     Cookie passCookie = CookieUtils.getCookie("password"); 

     if (nameCookie != null && passCookie != null) { 
      nameText.setValue(nameCookie.getValue()); 
      password.setValue(passCookie.getValue()); 
      saveUserPass.setValue(true); 
     } 

     w.setWidth("400px"); 
     w.setCaption(config.getTitle() + _.getString("LoginUserPasswdDialog.4")); 
     w.setResizable(false); 
     w.setClosable(false); 
     w.setModal(true); 
     w.center(); 

     ok.addListener(new ClickListener() { 
      public void buttonClick(ClickEvent event) { 
       String name = (String) nameText.getValue(); 
       String pass = (String) password.getValue(); 

       User u = userFactory.getUser(name, pass); 

       if (u != null) { 

        if ((Boolean) saveUserPass.getValue()) { 
         CookieUtils.makeCookie("username", name); 
         CookieUtils.makeCookie("password", pass); 
        } else { 
         CookieUtils.deleteCookie("username"); 
         CookieUtils.deleteCookie("password"); 
        } 

        userFactory.updateUser(u); 

        action.loggedIn(u); 
        parent.removeWindow(w); 
        return; 

       } else { 
        password.setValue(""); 
        WaresystemsUI.handle 
          .get() 
          .getMainWindow() 
          .showNotification(
            "", 
            _.getString("LoginUserPasswdDialog.3"), Notification.TYPE_ERROR_MESSAGE); //$NON-NLS-1$ 
        return; 
       } 
      } 

     }); 

     w.addComponent(v); 

     parent.addWindow(w); 
    } 

    @Override 
    public void setAction(LoggedAction loggedAction) { 
     this.action = loggedAction; 
    } 

} 

當然,你需要添加支持到web.xml:

<!-- SPRING --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:META-INF/spring/application-context.xml</param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<filter> 
    <filter-name>requestContextFilter</filter-name> 
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
    <init-param> 
     <param-name>threadContextInheritable</param-name> 
     <param-value>true</param-value> 
    </init-param> 
</filter> 

<filter-mapping> 
    <filter-name>requestContextFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 
2

您對Vaadin有一個非常有用的附加組件叫做SpringVaadinIntegration。

您可以使用Vaadin輕鬆保持乾淨的分隔,只需使用Spring @Autowired和服務進行數據檢索和修改即可。 我已經使用了Spring安全性,而且我對Vaadin沒有任何問題。 如果我沒有記錯的話,你可以使用@Scope註釋管理範圍,包含三個不同的值:Singleton(默認),Prototype和Session。

+0

可以請您給一些更多的細節。 – varun

+1

您可以查看加載項頁面:https://vaadin.com/directory#addon/springvaadinintegration – Morfic

1

你有沒有考慮使用Vaadin UIProvider機制。這種方式在UI中自動裝配完全透明。

你可以看看使用在github上該解決方案一個非常簡單的例子:spring-vaadin-example