HistoryPopStateEvent"

From Documentation
Line 33: Line 33:
 
@Listen("#btnHistoryAdd")
 
@Listen("#btnHistoryAdd")
 
public void addHistory() {
 
public void addHistory() {
Map<String, ?> map = new HashMap<String, Integer>();
+
Map<String, Object> map = new HashMap<String, Object>();
 
map.put("f1", position);
 
map.put("f1", position);
 
map.put("f2", "Clicked: " + System.currentTimeMillis());
 
map.put("f2", "Clicked: " + System.currentTimeMillis());

Revision as of 07:48, 31 October 2017


HistoryPopStateEvent

HistoryPopStateEvent

Employment/Purpose

The history pop state event used with onHistoryPopState to notify that user pressed BACK, FORWARD or others that causes the history changed (but still in the same desktop).

All root components of all pages of the desktop will receives this event.

Example

Catch a HistoryPopStateEvent in a MVC controller

<zk>
    <window id="win" apply="org.zkoss.MainController">
        <label id="lbl">Handle history states in MVC fashion.</label>
        <button id="btnHistoryAdd">Add History</button>
    </window>
</zk>
public class MainController extends SelectorComposer<Window> {
	private int position = 1;

	@Wire
	private Label lbl;

	@Listen("#btnHistoryAdd")
	public void addHistory() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f1", position);
		map.put("f2", "Clicked: " + System.currentTimeMillis());
		getSelf().getDesktop().pushHistoryState(map, "", "?p" + position);
	}

	@Listen("onHistoryPopState = #win")
	public void handleHistoryPopState(HistoryPopStateEvent event) {
		Map<String, ?> state = (Map<String, ?>) event.getState();
		if (state != null) {
			lbl.setLabel(state.get("f2"));
		}
	}
}
  • Line 12: Desktop object provides pushHistoryState API to push history status.
  • Line 15: Listening on the onHistoryPopState event.
  • Line 17: Get history state object map.

Supported events

Name
Event Type
None None

Supported Children

*NONE

Use cases

Version Description Example Location
     

Version History

Version Date Content
8.5.0 Oct 2017 ZK-3711: Support HTML5 history API



Last Update : 2017/10/31

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.