0

Communicate with included html (events, setting values)

asked 2021-02-25 20:15:05 +0800

assonaZkDev004 gravatar image assonaZkDev004
101 2

Hi :-)

I included a static html page in a zul file (see code). Now I want to retrieve events (button click on "#button1") from inside the html-page back to ZK (via Composer) and setting some text back into the html (input "#testbox"). Is that possible?

ZUL:

<zk>
<window id="htmlwindow" apply="de.assona.jive.jnh.HtmlPageComposer">
    <textbox id="targetBox" name="targetBox" value="" width="150px" />
</window>
</zk>

html:

<div>
    <div align="center">
        <h1>Included</h1>
    </div>
    <p>html page</p>    
    <button id="button1" value="Val01" >Click me</button>   
    <input id="testbox" type="text">
</div>

composer:

public class HtmlPageComposer extends SelectorComposer<Component> {
...

    // wire components
    @Wire
    private Window htmlwindow;

    @Override
    public void doAfterCompose(final Component comp) throws Exception {
    super.doAfterCompose(comp);

    Include htmlinclude = new Include();
    htmlinclude.setSrc("/WEB-INF/examples/test.html");
    this.htmlwindow.appendChild(htmlinclude);
}

Thank you

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-26 14:37:21 +0800

cor3000 gravatar image cor3000
6280 2 7

YES that's possible: see this example

https://zkfiddle.org/sample/36bqseb/1-communicate-with-included-html

I avoided the Include component since it switches to "defer" in this case making things slightly more complicated (unnecessary for your case). Instead I use an Idspace component avoiding ID clashes with other components. and create the components directly from HTML. Be aware that this creates a ZK component for each HTML element (using the XHTML component set, so you'll need the zhtml.jar dependency).

If you need something more memory efficient, consider combining native elements with xhtml components. (For smaller included html fragments this shouldn't matter.)

See here for a comparison of different namespaces.

link publish delete flag offensive edit

Comments

Thank you VERY much, that is a nice and elegant solution! And also thank you for the hints of memory efficiency!

assonaZkDev004 ( 2021-02-26 15:43:04 +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-02-25 20:15:05 +0800

Seen: 9 times

Last updated: Feb 26 '21

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