GwtEvent.Type<H> type, H handler) {
return eventBus.addHandler(type, handler);
}
+
+ /**
+ * Calls {@link ComponentConnector#flush()} on the active connector. Does
+ * nothing if there is no active (focused) connector.
+ */
+ public void flushActiveConnector() {
+ ComponentConnector activeConnector = getActiveConnector();
+ if (activeConnector == null) {
+ return;
+ }
+ activeConnector.flush();
+ }
+
+ /**
+ * Gets the active connector for focused element in browser.
+ *
+ * @return Connector for focused element or null.
+ */
+ private ComponentConnector getActiveConnector() {
+ Element focusedElement = Util.getFocusedElement();
+ if (focusedElement == null) {
+ return null;
+ }
+ return Util.getConnectorForElement(this, getUIConnector().getWidget(),
+ focusedElement);
+ }
}
*/
public TooltipInfo getTooltipInfo(Element element);
+ /**
+ * Called for the active (focused) connector when a situation occurs that
+ * the focused connector might have buffered changes which need to be
+ * processed before other activity takes place.
+ * <p>
+ * This is currently called when the user changes the fragment using the
+ * back/forward button in the browser and allows the focused field to submit
+ * its value to the server before the fragment change event takes place.
+ * </p>
+ */
+ public void flush();
+
}
}
/**
- * Gets the currently focused element for Internet Explorer.
+ * Gets the currently focused element.
*
- * @return The currently focused element
+ * @return The active element or null if no active element could be found.
*/
- public native static Element getIEFocusedElement()
+ public native static Element getFocusedElement()
/*-{
if ($wnd.document.activeElement) {
return $wnd.document.activeElement;
return null;
}-*/
;
+
+ /**
+ * Gets the currently focused element for Internet Explorer.
+ *
+ * @return The currently focused element
+ * @deprecated Use #getFocusedElement instead
+ */
+ @Deprecated
+ public static Element getIEFocusedElement() {
+ return getFocusedElement();
+ }
/**
* Kind of stronger version of isAttached(). In addition to std isAttached,
protected String getIcon() {
return getResourceUrl(ComponentConstants.ICON_RESOURCE);
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ComponentConnector#flush()
+ */
+ public void flush() {
+ // No generic implementation. Override if needed
+ }
}
String newFragment = event.getValue();
// Send the location to the server if the fragment has changed
+ // and flush active connectors in UI.
if (!newFragment.equals(currentFragment) && connection != null) {
currentFragment = newFragment;
+ connection.flushActiveConnector();
connection.updateVariable(id, UIConstants.LOCATION_VARIABLE,
Window.Location.getHref(), true);
}
@Override
public void onBeforeShortcutAction(Event e) {
- getWidget().synchronizeContentToServer();
+ flush();
}
@Override
public VRichTextArea getWidget() {
return (VRichTextArea) super.getWidget();
+ }
+
+ @Override
+ public void flush() {
+ getWidget().synchronizeContentToServer();
};
}
@Override
public void onBeforeShortcutAction(Event e) {
+ flush();
+ }
+
+ @Override
+ public void flush() {
getWidget().valueChange(false);
}
--- /dev/null
+package com.vaadin.tests.components.uitest;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.server.Page.UriFragmentChangedEvent;
+import com.vaadin.server.Page.UriFragmentChangedListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+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.VerticalLayout;
+
+public class BackButtonTest extends AbstractTestUI {
+
+ private VerticalLayout layout;
+
+ private String value = "Hello";
+ private Page1 p1;
+ private Page2 p2;
+
+ @Override
+ public void setup(VaadinRequest request) {
+ getPage().setUriFragment("page1");
+
+ layout = new VerticalLayout();
+ addComponent(layout);
+
+ p1 = new Page1();
+ addComponent(p1);
+
+ p2 = new Page2();
+ getPage().addUriFragmentChangedListener(
+ new UriFragmentChangedListener() {
+
+ @Override
+ public void uriFragmentChanged(UriFragmentChangedEvent event) {
+ String f = event.getUriFragment();
+ if ("page2".equals(f)) {
+ showPage2();
+ }
+
+ if ("page1".equals(f)) {
+ showPage1();
+ }
+ }
+ });
+ }
+
+ class Page1 extends VerticalLayout {
+ Label l = new Label();
+
+ public Page1() {
+ setSizeFull();
+ l.setCaption("Data from Page 1 : " + value);
+ addComponent(l);
+
+ Button b = new Button("Go to Page 2", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ l.setCaption("Data from Page 1 : " + value);
+ getPage().setUriFragment("page2");
+ }
+ });
+ addComponent(b);
+ }
+ }
+
+ private void showPage2() {
+ removeComponent(p1);
+ p2.f.setValue("");
+ addComponent(p2);
+ }
+
+ private void showPage1() {
+ removeComponent(p2);
+ addComponent(p1);
+ }
+
+ class Page2 extends VerticalLayout {
+ private final TextField f = new TextField();
+
+ public Page2() {
+ setSizeFull();
+
+ addComponent(f);
+ f.addValueChangeListener(new ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ value = f.getValue();
+ p1.l.setCaption("Data from Page 2 : " + value);
+ }
+ });
+
+ Button b = new Button("Go Back", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ getPage().setUriFragment("page1");
+ }
+ });
+ addComponent(b);
+ addComponent(new Label(
+ "Go back with the back button without creating a blur event on the text field. Text should transfer to page1 label."));
+ }
+
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 9949;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}