0

zul apply to nested classes

asked 2021-09-17 18:18:26 +0800

AlfredoGuiral gravatar image AlfredoGuiral
1

updated 2021-09-22 15:52:56 +0800

hawk gravatar image hawk
2874 1 5
http://hawkphoenix.blogsp... ZK Team

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

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-09-22 17:58:51 +0800

hawk gravatar image hawk
2874 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2021-09-22 19:05:30 +0800

cor3000 gravatar image cor3000
6168 2 7
ZK Team

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

link publish delete flag offensive edit

Comments

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
2 followers

RSS

Stats

Asked: 2021-09-17 18:18:26 +0800

Seen: 10 times

Last updated: Sep 22

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