首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >集成弹簧和金刚

集成弹簧和金刚
EN

Stack Overflow用户
提问于 2013-10-04 06:49:52
回答 4查看 2.7K关注 0票数 2

把Spring和vaadin集成在一起好吗?我希望在视图层和弹簧中使用vaadin作为我的服务。到目前为止,我还没有找到任何完整的集成解决方案。对于管理解决方案或ERP之类的生产应用程序来说,这是一个好主意吗?

  • 应用程序的设计可以是什么?
  • 如何在应用层之间保持清晰的分离?
  • 关于Vaadin与spring安全集成的问题?
  • 如何管理春豆的范围?

而且,与spring相比,任何人都能分享这种集成的优缺点吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-10-17 23:19:52

春天你根本不需要任何特殊的金库加载项。只需对您希望与spring集成的每个组件使用aspectj和@Configurable注释以及@Autowired。如下所示:

代码语言:javascript
复制
@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添加支持:

代码语言:javascript
复制
<!-- 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>
票数 0
EN

Stack Overflow用户

发布于 2013-10-04 09:07:15

对于Vaadin,您有一个非常有用的附加组件,称为SpringVaadinIntegration。

您可以很容易地使用Vaadin来保持一个干净的分离,只需使用Spring @Autowired和服务进行数据检索和修改。我使用了Spring安全,我对Vaadin没有任何问题。如果我没记错的话,您可以使用@Scope注释来管理范围,其中包含三个不同的值: Singleton (默认值)、Prototype和Session。

票数 2
EN

Stack Overflow用户

发布于 2013-10-27 21:46:07

你考虑过使用Vaadin UIProvider机制。这样,UI中的自动连接就完全透明了。

您可以查看一个在github上使用此解决方案的非常简单的示例:spring示例

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19175029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档