T - The data typepublic class NavigationModel<T> extends Object implements Serializable
Apply component.
A typical usage is that you can get each NavigationLevel by NavigationLevel.getChild() recursively.
NavigationModel. Add some data by calling put method.
The data is associated with a path. Data is stored like a tree hierarchy.
NavigationModel<String> navModel = new NavigationModel<String>();
navModel.put("Step 1", "step1.zul");
navModel.put("Step 1/Step 1-1", "step1-1.zul");
navModel.put("Step 2", "step2.zul");
navModel.put("Step 2/Step 2-1", "step2-1.zul");
navModel.put("Step 2/Step 2-2", "step2-2.zul");
navModel.put("Step 2/Step 2-2/Step 2-2-1", "step2-2-1.zul");
navModel.put("Step 2/Step 2-2/Step 2-2-2", "step2-2-2.zul");
navModel.put("Step 3", "step3.zul");
By using <apply> tags, we can include and navigate this zul files in a single page.
Calling navigateTo can navigate to the path.
The context is a Map to put something useful.
<apply level1="@load(vm.navModel.root)"
templateURI="@load(level1.current)"
context="@load(level1.context)"/>
By using the same approach, get child level navigation recursively in these included zul files.
<apply level2="@load(level1.child)"
templateURI="@load(level2.current)"
context="@load(level2.context)"/>
Add a link or button to navigate what you want in the same level.
For instance, level1 can be used to navigate through Step 1 to Step 3.
<a label="Step 2"
onClick='level1.setContext(Collections.singletonMap("hello", "world")).navigateTo("Step 2")' />
Section B/Sub Section C/My Item.
By default it is separated by / symbol and recognized as keys in each level.
Sometimes we may want to use / in the key name. Using a path string could get the unexpected result.
There are another methods that accept String[] instead of path string to avoid this issue.
addEventListener(EventListener) will be invoked.
The event object is NavigationEvent.Apply,
Serialized Form| Constructor and Description |
|---|
NavigationModel() |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(org.zkoss.zk.ui.event.EventListener<NavigationEvent<T>> listener)
Adds a listener to the list that's notified each time a change
to the model occurs.
|
void |
append(String[] levels,
String key,
T data)
Appends the data after the specific path.
|
void |
append(String path,
String key,
T data)
Appends the data after the specific path.
|
protected void |
fireEvent(NavigationLevel<T> level,
NavigationEvent.Type type,
org.zkoss.zuti.zul.NavigationNode<T> node) |
NavigationLevel<T> |
getRoot()
Gets the first navigation level.
|
void |
insertBefore(String[] levels,
String key,
T data)
Inserts the data before the item of specific levels.
|
void |
insertBefore(String path,
String key,
T data)
Inserts the data before the specific path.
|
void |
navigateTo(String key)
A shortcut of
getRoot().navigateTo(String). |
void |
navigateToByPath(String path)
Navigates to the specified path.
|
void |
navigateToByPath(String[] levels)
Navigates to the specified levels.
|
T |
put(String[] levels,
T data)
Puts the data to the path.
|
T |
put(String path,
T data)
Puts the data to the path.
|
T |
remove(String path)
Removes the data associated with the specific path.
|
T |
remove(String[] levels)
Removes the data associated with the specific levels.
|
void |
removeEventListener(org.zkoss.zk.ui.event.EventListener<NavigationEvent<T>> listener)
Removes a listener from the list that's notified each time
a change to the model occurs.
|
public T put(String path, T data)
path exists.
If any / symbol is included in the path string,
it is suggested to call put(String[], Object) instead.path - a path string. Will be separated into levels by / symbols. Like A/B/Cdata - a datapath, or null if there was no mapping.public T put(String[] levels, T data)
levels exists.levels - an array that contains each level keys as a pathdata - a datalevels, or null if there was no mapping.public void append(String path, String key, T data)
path - a path string. Will be separated into levels by / symbols. Like A/B/Ckey - an item key. Must be unique in the same leveldata - a dataIllegalArgumentException - if the path is invalid, the key is invalid or duplicated in the same levelpublic void append(String[] levels, String key, T data)
levels - an array that contains each level keys as a pathkey - an item key. Must be unique in the same leveldata - a dataIllegalArgumentException - if the path is invalid, the key is invalid or duplicated in the same levelpublic void insertBefore(String path, String key, T data)
path - a path string. Will be separated into levels by / symbols. Like A/B/Ckey - an item key. Must be unique in the same leveldata - a dataIllegalArgumentException - if the path is invalid, the key is invalid or duplicated in the same levelpublic void insertBefore(String[] levels, String key, T data)
levels - an array that contains each level keys as a pathkey - an item key. Must be unique in the same leveldata - a dataIllegalArgumentException - if the path is invalid, the key is invalid or duplicated in the same levelpublic T remove(String path)
path - a path string. Will be separated into levels by / symbols. Like A/B/CIllegalArgumentException - the path is invalidpublic T remove(String[] levels)
levels - an array that contains each level keys as a pathIllegalArgumentException - the path is invalidpublic void navigateTo(String key)
getRoot().navigateTo(String).key - the item keypublic NavigationLevel<T> getRoot()
public void navigateToByPath(String path)
path - a path string. Will be separated into levels by / symbols. Like A/B/CIllegalArgumentException - if the path is invalidpublic void navigateToByPath(String[] levels)
levels - an array that contains each level keys as a pathIllegalArgumentException - if the path is invalidpublic void addEventListener(org.zkoss.zk.ui.event.EventListener<NavigationEvent<T>> listener)
listener - Listener objectpublic void removeEventListener(org.zkoss.zk.ui.event.EventListener<NavigationEvent<T>> listener)
listener - Listener objectprotected void fireEvent(NavigationLevel<T> level, NavigationEvent.Type type, org.zkoss.zuti.zul.NavigationNode<T> node)
Copyright © 2021. All rights reserved.