That is how to refer outer anonymous class from inner anonymous class? Is calling method of anonymous outer class (although it is inner) from anonymous inner class of that outer class in general? Is is possible in Java?

I tried this.getParent() in the onClick() method. But it fails. And link extend AbstractLink which further extends WebMarkupContainer, there is no onClick() method in the super (s). Although onClick() of Link is abstract. Isn't it? How can I call super.onClick()? What about calling method of anonymous outer class (although it is inner) from anonymous inner class of that outer class in general? Is is possible in Java?
–
Tapas BoseApr 17 '11 at 18:14

@Tapas a) what does "it fails" mean? This is a standard method, and it always works b) about super, my mistake, I thought you were overrriding the removeLink()
–
Sean Patrick FloydApr 18 '11 at 4:38

1) sorry my fault. Because I tried this.getParent() which was returning ListItem, so now I did (ListView) this.getParent().getParent() and it worked. Also (ListView) this.findParent(ListView.class) worked fine. So both of them worked. Thanks. 2) I have a question regarding the code snippet I gave in my first post. What is the need to call listView.removeAll(). After adding stateChange to Link, we invoked ListItem.modelChanging(), then remove the item and called modelChanged(), what is the use of removeAll()? 3) What made the page reloading? Thank you.
–
Tapas BoseApr 18 '11 at 5:32

I believe the code below will work - declared variables are accessible from the inner class as long as they are declared final, so you can declare a variable that holds the ListView instance and use it from your inner class, as I did in the example below. Please note that I didn't compile this code, but I see no reason for it not to work. Just remember that the variable must be declared final.

The simple answer is: don't use nested anonymous classes. They're an absolute nightmare to read and to maintain anyway. As a rule of thumb, if your class is going to have more than two methods or more than five lines of code in the method bodies, it is better to make it a proper, named class.

That is sound advise in many cases, but impractical with Wicket. The behavior of simple components, (like a text placeholder or form component) are often defined by overriding methods from parent classes. If you were to create a proper class for each of these you'd have dozens of classes for even simple pages.
–
perilandmishapApr 17 '11 at 23:28

I use anonymous inner class in Swing too. And I love to use it.
–
Tapas BoseApr 18 '11 at 5:36

I agree that anonymous classes shouldn't be over-used, but a listener-based framework like wicket becomes a nightmare with 100s of trivial classes without them
–
Sean Patrick FloydApr 18 '11 at 8:54

@perilandmishap Note that I didn't say on every occasion and I didn't say you should use top level classes. There's indeed some advantage of an anonymous inner class over a named inner class, but all that is lost the moment you try to do non-trivial things.
–
biziclopApr 18 '11 at 9:24