Permalink
Browse files

Updated to demontrate session verses service object injection

  • Loading branch information...
1 parent 36ad8ea commit fe8bc76b03ea81dee5f0b057eaa47870e6ab1786 @navinpeiris committed Jun 14, 2011
@@ -5,6 +5,9 @@
package com.navinpeiris.vaadin_spring;
+import javax.annotation.PostConstruct;
+
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -20,14 +23,24 @@
@Component
@Scope("session")
public class MainWindow extends Window {
-
private static final long serialVersionUID = 1L;
+ private static int instanceId = 0;
+
+ @Autowired
+ private TextLabelService textLabelService;
+
public MainWindow() {
super(VaadinSpringDemoApplication.APPLICATION_TITLE);
- final Label label = new Label(VaadinSpringDemoApplication.APPLICATION_TITLE);
+ instanceId++;
+
+ addComponent(new Label(VaadinSpringDemoApplication.APPLICATION_TITLE));
+ }
- addComponent(label);
+ @PostConstruct
+ public void addInstanceLabels() {
+ addComponent(new Label("MainWindow instanceId: " + instanceId));
+ addComponent(new Label(textLabelService.getInstanceText()));
}
}
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011 Navin Peiris <navin.peiris@gmail.com>, Melbourne, Australia.
+ * All Rights Reserved.
+ */
+
+package com.navinpeiris.vaadin_spring;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * A dummy service that should be shared between all user sessions.
+ *
+ * @author Navin Peiris
+ * @since 1.0.0
+ */
+@Component
+public class TextLabelService {
+
+ private static int instanceId = 0;
+
+ public TextLabelService() {
+ instanceId++;
+ }
+
+ public String getInstanceText() {
+ return "TextLabelService instanceId: " + instanceId;
+ }
+}
@@ -27,7 +27,6 @@
@Override
public void init() {
- System.out.println("Main Window: " + mainWindow);
setMainWindow(mainWindow);
}

0 comments on commit fe8bc76

Please sign in to comment.