-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZK-5764: Unable to call original method when using custom ViewModelAn…
…notationResolver
- Loading branch information
1 parent
754c7a2
commit 42f06f1
Showing
9 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
zktest/src/main/java/org/zkoss/zktest/test2/B101_ZK_5764VM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* B101_ZK_5764VM.java | ||
Purpose: | ||
Description: | ||
History: | ||
Fri Aug 02 12:50:22 CST 2024, Created by jameschu | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.test2; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.zkoss.bind.annotation.Command; | ||
import org.zkoss.bind.init.ViewModelAnnotationResolvers; | ||
import org.zkoss.zk.ui.util.Clients; | ||
|
||
/** | ||
* @author jameschu | ||
*/ | ||
public class B101_ZK_5764VM { | ||
@Command | ||
public void update() { | ||
try { | ||
Method update = ViewModelAnnotationResolvers.getOriginalMethod(this, this.getClass().getMethod("update")); | ||
Clients.log(update.getDeclaringClass().getName()); | ||
} catch (NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
zktest/src/main/java/org/zkoss/zktest/test2/B101_ZK_5764ViewModelAnnotationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
B101_ZK_5764ViewModelAnnotationHandler.java | ||
Purpose: | ||
Description: | ||
History: | ||
Fri Aug 02 12:50:22 CST 2024, Created by jameschu | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.test2; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
|
||
import org.zkoss.bind.ViewModelAnnotationResolver; | ||
|
||
/** | ||
* @author jameschu | ||
*/ | ||
public class B101_ZK_5764ViewModelAnnotationHandler implements ViewModelAnnotationResolver { | ||
public <T extends Annotation> T getAnnotation(Method method, Class<T> annotationClass) { | ||
return method.getAnnotation(annotationClass); | ||
} | ||
|
||
public <T extends Annotation> T getAnnotation(Class clazz, Class<T> annotationClass) { | ||
return (T) clazz.getAnnotation(annotationClass); | ||
} | ||
|
||
public Method getOriginalMethod(Object base, Method method) { | ||
try { | ||
String targetMethodName = "update"; | ||
if (targetMethodName.equals(method.getName())) { | ||
return this.getClass().getMethod(targetMethodName); | ||
} | ||
} catch (NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return method; | ||
} | ||
|
||
public void update() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<zk> | ||
<listener> | ||
<listener-class>org.zkoss.zktest.test2.B101_ZK_5764ViewModelAnnotationHandler</listener-class> | ||
</listener> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
B101-ZK-5764.zul | ||
Purpose: | ||
Description: | ||
History: | ||
Fri Aug 02 12:50:22 CST 2024, Created by jameschu | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk xmlns:w="client"> | ||
<label multiline="true"><![CDATA[ | ||
1. Add the following setting in zk.xml | ||
<listener> | ||
<listener-class>org.zkoss.zktest.test2.B101_ZK_5764ViewModelAnnotationHandler</listener-class> | ||
</listener> | ||
2. Click button, should see log "org.zkoss.zktest.test2.B101_ZK_5764ViewModelAnnotationHandler" | ||
]]></label> | ||
<div viewModel="@id('vm') @init('org.zkoss.zktest.test2.B101_ZK_5764VM')"> | ||
<button label="call cmd update" onClick="@command('update')"/> | ||
</div> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
zktest/src/test/java/org/zkoss/zktest/zats/test2/B101_ZK_5764Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* B101_ZK_5764Test.java | ||
Purpose: | ||
Description: | ||
History: | ||
Fri Aug 02 12:50:22 CST 2024, Created by jameschu | ||
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.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import org.zkoss.test.webdriver.ExternalZkXml; | ||
import org.zkoss.test.webdriver.ForkJVMTestOnly; | ||
import org.zkoss.zats.mimic.DesktopAgent; | ||
import org.zkoss.zktest.zats.ZATSTestCase; | ||
|
||
/** | ||
* @author jameschu | ||
*/ | ||
@ForkJVMTestOnly | ||
public class B101_ZK_5764Test extends ZATSTestCase { | ||
@RegisterExtension | ||
public static final ExternalZkXml CONFIG = new ExternalZkXml("/test2/B101-ZK-5764-zk.xml"); | ||
|
||
@Test | ||
public void test() { | ||
DesktopAgent desktopAgent = connect(); | ||
desktopAgent.query("button").click(); | ||
assertEquals("org.zkoss.zktest.test2.B101_ZK_5764ViewModelAnnotationHandler", desktopAgent.getZkLog().get(0)); | ||
} | ||
} |