Skip to content

ZK How to render bread crumb without using shadow component

For the file browser that I’m trying to make I need a navigator with breadcrumb style. I found some example using <forEach> tag that isn’t included into the community edition. The Questions are:

  1. Is there a way to render a dynamic text/anchor (link) like bread crumb? Or is there a way to overwrite some <div id="someContainer" /> so the div as placeholder can be write with some children in MVVM way?
  2. So the breadcrumb will have an action when the link is click. When the link is clicked it must update the content of another ListModelList object and update itself if the previous crumb is clicked. How can I do that in MVVM style?

Fiddle example but using shadow component <forEach>

Some zul code:

    <window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('')">
            <listbox vflex="true" hflex="1" model="@load(vm.files)"
                id="fileBrowser" selectedItem="@bind(vm.selectedFile)">
                    <auxheader colspan="3">File List</auxheader>
                    <auxheader colspan="3">
                            <!-- breadcrumb, implemented later -->
                            <div id="placeHolder" />
                    <listheader label="Name" />
                    <listheader label="Size" />
                    <listheader label="Modified" />
                <template name="model" var="file">
                    <!-- This is the model that need to be updated when bredcrumb is clicked -->
                        <listcell label="@load(" />
                        <listcell label="@load(file.length())" />
                        <listcell label="@load(file.lastModified())" />
        <separator />

Thanks for the help.


in CE you can use children binding which has a less intuitive syntax, and works less efficient (however not significant in case of breadcrumbs)

Here the updated example.

    <hlayout style="border:2px black solid;" children="@load(vm.breadcrumbs)">
      <template name="children">
            <nodom if="${each ne vm.currentPage}">
              <label style="text-decoration: underline blue; cursor:pointer;" value="${each.label}"
                     onClick="@command('navigateToPage', page=each)" />
              <label value=" > "/>
            <label if="${each eq vm.currentPage}" style="font-weight: bold;" value="${each.label}"/>

A children binding is added to the parent and will iterate over the items in the collection using the <template name="children">, <choose>/<when> can be replaced by the static if attribute. Even if static, the expression will evaluate again when the children are re-rendered (so it’s kind of dynamic).

In the view model you have to notify change the breadCrumbs property which will then re-render all children. (Since it’s only a few elements the impact shouldn’t be significant)