diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2012-10-18 13:40:24 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-10-18 13:40:24 +0000 |
commit | 81f4c52f79b1c79d5b3bf4299874f20dbf0d90a5 (patch) | |
tree | d189b2e3a6e782b461db25a50729d9f22a86429c /uitest | |
parent | 94bec9fc11681141588f18207b27008d747c39e1 (diff) | |
parent | 8545d39358d57c1503023ed6c890a8ef4f8033fc (diff) | |
download | vaadin-framework-81f4c52f79b1c79d5b3bf4299874f20dbf0d90a5.tar.gz vaadin-framework-81f4c52f79b1c79d5b3bf4299874f20dbf0d90a5.zip |
Merge "Update mini tutorial code"
Diffstat (limited to 'uitest')
4 files changed, 159 insertions, 2 deletions
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java index 430da55fa1..c849cdce36 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java @@ -21,20 +21,29 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.minitutorials.v7a3.Refresher.RefreshListener; import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; @Widgetset(TestingWidgetSet.NAME) public class RefresherTestUI extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - Refresher refresher = new Refresher(); + final Refresher refresher = new Refresher(); refresher.extend(this); + refresher.setInterval(1000); refresher.addListener(new RefreshListener() { @Override public void refresh(Refresher source) { System.out.println("Got refresh"); } }); + addComponent(new Button("Remove refresher", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + removeExtension(refresher); + } + })); } @Override diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java b/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java new file mode 100644 index 0000000000..0356b4c5a8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b5/HandlingLogout.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.minitutorials.v7b5; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServletService; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; + +public class HandlingLogout extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(new Button("Logout", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + logout(); + } + })); + } + + private void logout() { + // Close the VaadinServiceSession + getUI().getSession().close(); + + // Invalidate underlying session instead if login info is stored there + // VaadinService.getCurrentRequest().getWrappedSession().invalidate(); + + // Redirect to avoid keeping the removed UI open in the browser + getUI().getPage().setLocation(getLogoutPageLocation()); + } + + protected String getLogoutPageLocation() { + return VaadinServletService.getCurrentRequest().getContextPath() + + "logout.html"; + } + + @Override + protected String getTestDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9646); + } + +} diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java new file mode 100644 index 0000000000..bc96152880 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.minitutorials.v7b5; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinService; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +//Remove comment to preserve UI value when reloading +//@PreserveOnRefresh +public class SettingReadingSessionAttributesUI extends UI { + + private String value; + + private VerticalLayout statusHolder = new VerticalLayout(); + private TextField textField = new TextField(); + + @Override + protected void init(VaadinRequest request) { + addComponent(statusHolder); + addComponent(textField); + addComponent(new Button("Set new values", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + String value = textField.getValue(); + + saveValue(SettingReadingSessionAttributesUI.this, value); + } + })); + addComponent(new Button("Reload page", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + getPage().setLocation(getPage().getLocation()); + } + })); + + showValue(this); + } + + private static void saveValue(SettingReadingSessionAttributesUI ui, + String value) { + // Save to UI instance + ui.value = value; + // Save to VaadinServiceSession + ui.getSession().setAttribute("myValue", value); + // Save to HttpSession + VaadinService.getCurrentRequest().getWrappedSession() + .setAttribute("myValue", value); + + // Show new values + showValue(ui); + } + + private static void showValue(SettingReadingSessionAttributesUI ui) { + ui.statusHolder.removeAllComponents(); + ui.statusHolder.addComponent(new Label("Value in UI: " + ui.value)); + ui.statusHolder.addComponent(new Label( + "Value in VaadinServiceSession: " + + ui.getSession().getAttribute("myValue"))); + ui.statusHolder.addComponent(new Label("Value in HttpSession: " + + VaadinService.getCurrentRequest().getWrappedSession() + .getAttribute("myValue"))); + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java index 769f6330a9..13e8d8bc1d 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java @@ -3,5 +3,5 @@ package com.vaadin.tests.widgetset.client.minitutorials.v7a3; import com.vaadin.shared.communication.SharedState; public class RefresherState extends SharedState { - public int interval = 1000; + public int interval; }
\ No newline at end of file |