zhtml + template problem

asked 2021-08-26 16:19:40 +0800

Arsen gravatar image Arsen
384 5

Good day. Here is my zhtml

<x:html xmlns="http://www.zkoss.org/2005/zul"
  <div viewModel="@id('vm') @init('com.mira.vseveda.web.pub.UnsubscribeViewModel')">
    <div children="@init(vm.testList)">
      <template name="children">
        <checkbox label="@load(each)"/>

And view model

public class UnsubscribeViewModel {
  public List<String> getTestList(){
    return List.of("one", "two", "three");

I expect to see 3 checkboxes in rendered html, but I get 3 spans

<div id="mXBQ2" class="z-div">
  <div id="mXBQ3" class="z-div">
    <span id="mXBQ4" class="z-label">one</span>
    <span id="mXBQ5" class="z-label">two</span>
    <span id="mXBQ6" class="z-label">three</span>

No matter what I put inside template I get 3 spans, template is completely ignored. But if change zhtml to zul

<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.spring.DelegatingVariableResolver" ?>

<div xmlns="http://www.zkoss.org/2005/zul" viewModel="@id('vm') @init('com.mira.vseveda.web.pub.UnsubscribeViewModel')">
  <div children="@load(vm.testList)">
    <template name="children">
      <checkbox label="@load(each)"/>

then template is working as expected and I see 3 checkboxes in result html.

How can I make template work in my zhtml?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-27 12:05:34 +0800

cor3000 gravatar image cor3000
6094 2 7
ZK Team

I guess, what you're missing is the fact that the <template> element is not a zul component (instead those are special ZUML elements which control how components are created). When running your example code I get an exception ... which indicates what's wrong (more or less clearly).

    Component definition not found: template in [LanguageDefinition: xul/html]

Instead you have to declare and use the according namespace "zk" for these special elements (.zhtml files have different parsing rules than .zul files)

<x:html xmlns="http://www.zkoss.org/2005/zul"

Besides that I am not sure what the src attribute at the root element x:html does. In my tests it was plainly rendered to the DOM element, I assume you have your own custom processing handling that.

link publish delete flag offensive edit


Thanks you! This solves my problem.

Arsen ( 2021-08-27 12:22:35 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2021-08-26 16:19:40 +0800

Seen: 7 times

Last updated: Aug 27

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More