0

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"
        xmlns:x="xhtml"
        src="/components/public-page-template.html">
  <div viewModel="@id('vm') @init('com.mira.vseveda.web.pub.UnsubscribeViewModel')">
    <div children="@init(vm.testList)">
      <template name="children">
        <checkbox label="@load(each)"/>
      </template>
    </div>
  </div>
</x:html>

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>
  </div>
</div>

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)"/>
    </template>
  </div>
</div>

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
1

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

cor3000 gravatar image cor3000
6280 2 7

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).

org.zkoss.zk.ui.metainfo.DefinitionNotFoundException: 
    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"
        xmlns:x="xhtml"
        xmlns:zk="zk"
        src="/components/public-page-template.html">
...
   <zk:template>
   ...
   </zk:template>

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

Comments

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

Follow
1 follower

RSS

Stats

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

Seen: 7 times

Last updated: Aug 27 '21

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