https://www.zkoss.org/wiki/ZUMLReference/ELExpressions/Core_Methods/new1
cor3000 ( 2021-09-22 19:08:05 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I have an outer class holding a couple of inner classes like these:
package parameter;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
public class A extends SelectorComposer<Component> {
public A() {
System.out.println("A");
}
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
public class AA {
public AA() {
// TODO Auto-generated constructor stub
System.out.println("AA");
}
}
public class AB {
public AB() {
System.out.println("AB");
}
}
}
When I try to apply any of the inner classes in a zul file like this
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Manage" border="normal" height="100%" apply="parameter.A.AA"/>
</zk>
I get this error
java.lang.ClassNotFoundException: parameter.A.AA
Any clue please ?
Thanks
Alfredo
The correct class name for a nested class is (use a '$' to separate the nested from the outer class name '.'):
apply="parameter.A$AA"
This would work for a static inner class. So in case you meant that you have to declare the inner class as static
.
public static class AA { ...
Non-static inner classes, parameter.A$AA
, need an instance of the outer class to instantiate properly. They don't "really" have a default constructor, so ZK can't instantiate it just by the classname. Instead you have to instantiate it by providing an instance of the outer class. This can be done with the new1
taglib function.
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk>
<window apply="${c:new1('parameter.A$AA', $composer)}" />
</zk>
$composer
is the default variable referencing the outer composer.
Here a runnable example:
https://zkfiddle.org/sample/2ra8bng/2-instantiate-nested-non-static-class
https://www.zkoss.org/wiki/ZUMLReference/ELExpressions/Core_Methods/new1
cor3000 ( 2021-09-22 19:08:05 +0800 )editAsked: 2021-09-17 18:18:26 +0800
Seen: 12 times
Last updated: Sep 22 '21
bug with intboxes on mobile devices
zk keikai-how to add custom button/label to formulabar?
zk-keikai- update multiple cells parallel at same time asynchronously
zk-keikai-How to auto fit column width based on text
zk-keikai-ClipboardPateEvent-called twice
Reference a spring bean from VariableResolver