Is there a way to refer to a non-static field of an outer class from a static nested class?
Please see my code below:
public class TestComponent {
String value;
public void initialize(String value) {
this.value = value;
}
public static class TestLabel extends GenericForwardComposer {
Label testLabel;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
testLabel.setValue(value);
}
}
}
This code throws an error at testLabel.setValue(value) as I am trying to make a static reference to a non-static field. But, I need the value to be non-static and yet reference it in the static nested class's method. How do I do it?
You may notice how I instantiate TestComponent.java here: http://top.cs.vt.edu/~vsony7/patches/gfc.patch
The idea is to create two labels dynamically with two different values "Label 1" and "Label 2" and append them to two different Components i.e. vlayout1 and vlayout2. But, when I run this code, a label gets attached to each of the layouts but the value of both the labels is "Label 2". You can test this at:
The problem is that the two windows from testlabel.zul created by two calls to IncludeBuilder share the static class TestLabel. After the super.doAfterCompoe() the value of test label is set to "Label 2" in both the calls.
I am using Zk framework and ZK does not have an enclosing instance so the inner nested class TestLabel must be static.
Thanks, Sony