Button listener

I was wondering, as a New user, if this is a safe thing to do.
My doubt is based on the First Paragraph in the Vaadin book (6.2) pg 73
“Using captions or any other visible text is generally discouraged …”

Button b = new Button("mybtn",this);

Button b = new Button("mysecondbtn",this);

public void buttonClick(ClickEvent event){

String id =(String)( event.getButton).getData();

//process buttons based on this.


I prefer the use of anonymous inner classes for listeners because it basically shrinks the amount of code you need to write. So you should consider something like:

Button b = new Button(“mybtn”, new Button.ClickListener() {

		public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
			// write your click handler code

I suppose it’s ok. One issue is with comparing the string keys; it is always better if things are checked compile-time. Perhaps storing the button references in member variables would be better, although it adds a bit clutter to the class.

Thanks for the response.

Using anonymous inner classes is not desirable for me, because I will be limited to the scope of the function in which the button is created.

Also making the buttons, say like 8 of them member variables is bit of code eyesore.

So , thanks just wanted to know, I risk no bug .