HistoryPopStateEvent"
From Documentation
(HistoryPopStateEvent) |
m (→Example) |
||
Line 14: | Line 14: | ||
= Example = | = Example = | ||
+ | Catch a <code>HistoryPopStateEvent</code> in a MVC controller | ||
+ | <source lang="xml" high=""> | ||
+ | <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> | ||
+ | </source> | ||
− | + | <source lang="java" high="12,17"> | |
+ | public class MainController extends SelectorComposer<Window> { | ||
+ | private int position = 1; | ||
+ | |||
+ | @Wire | ||
+ | private Label lbl; | ||
+ | |||
+ | @Listen("#btnHistoryAdd") | ||
+ | public void addHistory() { | ||
+ | Map<String, Integer> map = new HashMap<String, Integer>(); | ||
+ | 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")); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | * Line 12: Desktop object provide pushHistoryState API to push history status. | ||
+ | * Line 15: Listening on the onHistoryPopState event. | ||
+ | * Line 17: Get history state object map. | ||
=Supported events= | =Supported events= |
Revision as of 07:12, 31 October 2017
HistoryPopStateEvent
- Demonstration: N/A
- Java API: HistoryPopStateEvent
- JavaScript API: N/A
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, Integer> map = new HashMap<String, Integer>();
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 provide pushHistoryState API to push history status.
- Line 15: Listening on the onHistoryPopState event.
- Line 17: Get history state object map.
Supported events
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 |