You have a few different options:
1. Use an object like StringBuilder, which stores a string that is
modifiable.
2. Wrap your string in a custom object which can be final, acts like a
place holder.
3. ...
I generally use number 2, unless of coarse I am modifying the string, then
a StringBuilder should be used.
public class StringPlaceHolder {
public String theString = null;
}
public final StringPlaceHolder placeHolder = new StringPlaceHolder();
..your click handler..
public void onClick(ClickEvent event) {
...
placeHolder.theString = something;
}
This code may not be exactally correct, but should get the point across.
On Thursday, March 15, 2012 4:53:29 AM UTC-4, Gautam wrote:
> Hi,
> I am relatively new to GWT, I apologize if my doubt sounds juvenile.
>
> I have a requirement where I need to append contents to a String in a
> Button's ClickHandler. In the ClickHandler, i do something like this :
>
> String string = "";
> for(int i=0; i<Panel.getWidgetCount();
> i++)
> {
> Label l =
> (Label)Panel.getWidget(i);
> string = rb.getText();
> }
>
> I do this because the number of labels in the panel is decided at run-
> time only. My problem is that i want this "string" to be available
> outside the scope of the Button's ClickHandler. If i declare "string"
> outside the ClickHandler, i cannot access it because it is a non-final
> variable. If i use the keyword final with"string", i cannot modify it
> within the ClickHandler.
>
> What can i do here? I apologize once again if this sounds silly but i
> couldn't find a solution anywhere.
> Any help would be greatly appreciated.
>
> Thanks in advance.
>
> Regards,
> Gautam
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/o6NQoQR6OcUJ.
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.