v3ctor
v3ctor

Reputation: 105

GWT show value inserted into a texbox

I need to show the value inserted into textbox. I created this code:

public void onModuleLoad()
{
    TextBox textValue = new TextBox();
    textValue.getSelectedText();
    final String index = textValue.getValue().toString();

    Button button = new Button("button", new ClickHandler()
    {
        public void onClick(ClickEvent event)
        {

            Window.alert("You selected: " + index);

        }
    });

    RootPanel.get().add(textValue);
    RootPanel.get().add(button);
}

But the value does not appear in the window.

Can somebody help me please?

Upvotes: 1

Views: 137

Answers (2)

bNd
bNd

Reputation: 7630

Put textValue.getValue condition inside button onClick event.

public void onModuleLoad()
{
    final TextBox textValue = new TextBox();
    textValue.getSelectedText();


    Button button = new Button("button", new ClickHandler() {
        public void onClick(ClickEvent event)
        {
            final String index = textValue.getValue().toString();

            Window.alert("You selected: " + index);

        }
    });

    RootPanel.get().add(textValue);
    RootPanel.get().add(button);
}

Upvotes: 0

user902383
user902383

Reputation: 8640

if you want to display selected text, you should use getSelectedText, not getValue

try this

public void onModuleLoad()
        {
            final TextBox textValue = new TextBox();



            Button button = new Button("button", new ClickHandler()
            {
                public void onClick(ClickEvent event)
                {
                    final String index = textValue.getSelectedText();

                    Window.alert("You selected: " + index);

                }
            });

            RootPanel.get().add(textValue);
            RootPanel.get().add(button);
        }

Upvotes: 1

Related Questions