You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by eugenebalt <eu...@yahoo.com> on 2012/11/01 16:42:10 UTC

Unable to Traverse with IVisitor: Some Class Names Have "$1" at the end

I am using the IVisitor to traverse all components on the current page. I'm
printing the class names on the console.

visitChildren(new IVisitor() {

	@Override
	public Object component(Component arg0) {
		System.out.println(arg0.getClass().toString());
	             return IVisitor.CONTINUE_TRAVERSAL;
	}
			
});	

Most of the time, the class names are right, but sometimes, I don't get
Wicket org names, I get these:

com.mycompany.MyForm.MyPanel$1   ( <-- on a Button!)
com.mycompany.SomeForm$1           ( <-- on a Button!)

What's going on here, why can't I get the actual
org.apache.wicket.markup.html.form.Button class names?
	



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unable-to-Traverse-with-IVisitor-Some-Class-Names-Have-1-at-the-end-tp4653532.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unable to Traverse with IVisitor: Some Class Names Have "$1" at the end

Posted by eugenebalt <eu...@yahoo.com>.
Thanks. Working now.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unable-to-Traverse-with-IVisitor-Some-Class-Names-Have-1-at-the-end-tp4653532p4653538.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unable to Traverse with IVisitor: Some Class Names Have "$1" at the end

Posted by Alexander Cherednichenko <le...@gmail.com>.
hi Eugene.
Super class will do that for you -- when you create an anonymous subclass
of a button, its parent would be a Button.

So just print out parent class name if the component's class name contains
$ sign it will do the trick.

best wishes,
alex
On Nov 1, 2012 6:09 PM, "eugenebalt" <eu...@yahoo.com> wrote:

> Thanks Duesen, but if I get the superclass, how can I actually get the type
> of *this* class?
>
> I need to find out if the anonymous class is a Button, a TextField, a Link,
> etc.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Unable-to-Traverse-with-IVisitor-Some-Class-Names-Have-1-at-the-end-tp4653532p4653536.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Unable to Traverse with IVisitor: Some Class Names Have "$1" at the end

Posted by eugenebalt <eu...@yahoo.com>.
Thanks Duesen, but if I get the superclass, how can I actually get the type
of *this* class?

I need to find out if the anonymous class is a Button, a TextField, a Link,
etc.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unable-to-Traverse-with-IVisitor-Some-Class-Names-Have-1-at-the-end-tp4653532p4653536.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unable to Traverse with IVisitor: Some Class Names Have "$1" at the end

Posted by Carl-Eric Menzel <cm...@wicketbuch.de>.

> Most of the time, the class names are right, but sometimes, I don't
> get Wicket org names, I get these:
> 
> com.mycompany.MyForm.MyPanel$1   ( <-- on a Button!)
> com.mycompany.SomeForm$1           ( <-- on a Button!)
> 
> What's going on here, why can't I get the actual
> org.apache.wicket.markup.html.form.Button class names?

That's Java for you. When you create a button like this:

class MyPage {
  ...
  new Button() {
    ...
  }
}

...then you actually create a new class at that spot. It's anonymous,
so it doesn't have a really usable name, but internally, the compiler
and VM use <enclosingclassname>$<someindexvalue> to create that name.
Thus, you get MyPage$1 if this is the first anonymous subclass you
create within MyPage.

My usual solution to this is to not just print out the class name, but
first check whether the class name contains a "$", and if so, get the
superclass instead.

Carl-Eric

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org