Why is my ClickListener not firing on first click?

I have a table with several rows. When user click on a row the ItemClickListener enables a button:

testCaseTable.addItemClickListener(new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { groupForm.tcDetailsButton.setEnabled(true); System.out.println("_________________"); System.out.println("Item ID is: " + event.getItemId().toString()); System.out.println("Item is: " + event.getItem().toString()); System.out.println("Property ID is: " + event.getPropertyId().toString()); System.out.println("_________________"); } }); The first time I click the button, nothing happens. The second time I click the button, it fires properly and opens the browser window:

tcDetailsButton.addClickListener(new Button.ClickListener() {
/**
*
*/ private static final long serialVersionUID = 3726094749730769327L;
@Override
public void buttonClick(ClickEvent event) {
BrowserWindowOpener opener = new BrowserWindowOpener(EvoltwebUI.class);
opener.setResource(new ExternalResource("google.com"));
//url opener.setWindowName("_blank");
opener.extend(tcDetailsButton);
}
});

It appears that if I click on 2 rows in my table, then click on the button, it opens 1 browser tab. If I click on 3 rows, then click on the button, it opens 2 browser tabs, 4 rows clicked = 3 tabs opened, etc.

What could be causing this?

Hi Michael,
the BrowserWindowOpener extension set a click listener on the client side to the extended component.
This is why you first click does nothing; the first click invokes server side code that only tells the connector to add the click listener on client side.
When you click the button the second time first the client side listener opens the window and the the server side listener tells client side to add another click listener on the client side; this is way every time you click on the button you have one more window opened.

You shoul extend the button only once and before you click on it; otherwise you shoul try others solutions, for example the one discussed on this
thread

HTH
Marco

Thanks Marco. I was able to get this working correctly by declaring the BrowserOpener at the class level, and extending the button before the click happens. The clicklistener now looks like this:

 [code]

tcDetailsButton.addClickListener(new Button.ClickListener() {

        /**
         *
         */
        private static final long serialVersionUID = 3726094749730769327L;

        @Override
        public void buttonClick(ClickEvent event) {                
            
            opener.setResource(new ExternalResource("google.com")); //url
            opener.setWindowName("_blank");                            
                
        }
    });

[/code]

Hi Michael,
be aware that setting the resource on server side button click listener will affect only the next click because client side click listener that opens the window is fired before the server side listener.