Skip to content

Commit

Permalink
ZK-5551: Shadow Component ForEach adds fullfil listeners everytime th…
Browse files Browse the repository at this point in the history
…e syncModel method is called, doesn't clear them if component is removed
  • Loading branch information
jumperchen committed Sep 25, 2024
1 parent e544f84 commit 1a777f6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions zk/src/main/java/org/zkoss/zk/ui/impl/UiEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,10 @@ public void onEvent(Event evt) throws Exception {
for (int j = _targets.length; --j >= 0;)
_targets[j].removeEventListener(_evtnms[j], this); //one shot only

// Fix ZK-5551
if (_comp.getDesktop() == null && _comp.getPage() == null)
return; //already detached

final Execution exec = Executions.getCurrent();
execCreate0(
new CreateInfo(((WebAppCtrl) exec.getDesktop().getWebApp()).getUiFactory(), exec, _comp.getPage(),
Expand Down
1 change: 1 addition & 0 deletions zkdoc/release-note
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ZK 10.1.0
ZK-5756: a MatchMedia request causes java.lang.IllegalArgumentException
ZK-5589: a checkmark of a checkbox inside a caption is shifted unexpectedly
ZK-5455: Popup causes error if parent is removed during popup opening animation
ZK-5551: Shadow Component ForEach adds fullfil listeners everytime the syncModel method is called, doesn't clear them if component is removed

* Upgrade Notes
+ Remove Htmls.encodeJavaScript(), Strings.encodeJavaScript(), Strings.escape() with Strings.ESCAPE_JAVASCRIPT, and replace them with OWASP Java Encoder APIs instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* B101_ZK_5551Composer.java
Purpose:
Description:
History:
11:33 AM 2024/9/25, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zktest.test2;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Label;

/**
* @author jumperchen
*/
public class B101_ZK_5551Composer implements org.zkoss.zk.ui.util.Composer {
public void doAfterCompose(Component comp) {
String itemLabel = (String) comp.getParent().getAttribute("item");
Clients.log("executing composer for " + comp + " " + itemLabel + " page: " +comp.getPage());
comp.appendChild(new Label("itemLabel"));
}
}
35 changes: 35 additions & 0 deletions zktest/src/main/webapp/test2/B101-ZK-5551.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
B101-ZK-5551.zul
Purpose:
Description:
History:
2024/9/23, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
-->
<zk>
<zscript><![CDATA[
ListModelList model = new ListModelList();
int count = 0;
]]></zscript>

<button label="add dynamic item" onClick='model.add("item-" + ++count)'/>
<button label="clear model" onClick='model.clear()'/>
<button id="renderAll" label="render all"/>

<div>
<forEach items="${model}">
<div style="border: 1px solid red; height: 20px;"
fulfill="renderAll.onClick">
<custom-attributes item="${each}"/>
<div apply="org.zkoss.zktest.test2.B101_ZK_5551Composer"/>
</div>
</forEach>
</div>
</zk>
1 change: 1 addition & 0 deletions zktest/src/main/webapp/test2/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,7 @@ B90-ZK-4431.zul=A,E,Multislider
##zats##B101-ZK-5756.zul=A,E,ServerMVVM,Exception,MatchMedia,Data-racing
##manually##B101-ZK-5589.zul=A,E,Iceblue,Theme,Style,checkbox,caption,groupbox
##zats##B101-ZK-5455.zul=A,E,Popup,Data-racing,JS,Error
##zats##B101-ZK-5551.zul=A,E,fulfill,Shadow,ForEach,Model

##
# Features - 3.0.x version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* B101_ZK_5551Test.java
Purpose:
Description:
History:
5:41 PM 2024/9/24, Created by jumperchen
Copyright (C) 2024 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zktest.zats.test2;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import org.zkoss.test.webdriver.WebDriverTestCase;

/**
* @author jumperchen
*/
public class B101_ZK_5551Test extends WebDriverTestCase {
@Test
public void test() {
connect();
for (int i = 0; i < 3; i++) {
click(jq("@button:eq(0)"));
waitResponse();
}
click(jq("@button:eq(1)"));
waitResponse();
click(jq("@button:eq(2)"));
waitResponse();
String log = getZKLog();
assertEquals(0, log.split("executing composer for ").length - 1);

}
}

0 comments on commit 1a777f6

Please sign in to comment.