On Wed, Aug 25, 2010 at 4:19 AM, M. Eduard <[email protected]> wrote:
> Hi!
> I think most of you went through GWT Get Started material. It was
> based on StockWatcher project example.
> One detail there which doesn't let me complete it.
> The code which adds ClickHandler to button which removes Stock item
> from the table. For each row this button is dynamically added. The
> code is following:
> private void addStock(){
> final String symbol =
> newSymbolTextBox.getText().toUpperCase().trim();
> .....
> Button removeStockButton = new Button("x");
> removeStockButton.addStyleDependentName("remove");
> removeStockButton.addClickHandler(new ClickHandler() {
> public void onClick(ClickEvent event) {
> int removedIndex = stocks.indexOf(symbol);
> stocks.remove(removedIndex);
> stocksFlexTable.removeRow(removedIndex+1);
> }
> });
> ....
> }
> The thing that is not clear, how will be 'symbol' variable resolved in
> ClickHandler when actually the click will happen on remove button?! It
> was declared in another class method,
Well, does your code compile? Or are you desk-checking the sample?
Either way: the method variable "symbol" is declared in the scope of
addStock(), which is also the scope of the click handler. The "juicy bit" is
the modifier "final". We need this to ensure that the variable is accessible
inside the click handler.
which took place when stock was
> added, so it won't be accessible any more,
No, that's not the case. Can you justify this statement?
> particularly when sometime
> onClick() event will take place...
>
I think the answer to this assertion is: that's why the "final" modifier is
required. However, as noted above, the premise is faulty.
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.