Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4018178
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:57:03+00:00 2026-05-20T09:57:03+00:00

I am building a GWT component to behave much like the comments box here

  • 0

I am building a GWT component to behave much like the comments box here on stackoverflow, and other sites. I am trying to register listeners for KeyPress, Change and ONPASTE events that will update my status line with number of characters remaining, etc.

It works except it is always one character behind the actual number of characters in the text area. I set the max number of characters to 10. When I type the first character it still says, “10 characters remaining”. It doesn’t update the status line until I type the second character and then it is one off, it says 9 characters remaining when the second character is typed.

When I BACKSPACE or DELETE, it is also one off, when there are no characters it still says “9 characters remaining” until I press the BACKSPACE or DELETE a second time.

I am getting this behavior in both Firefox, Chrome and Internet Explorer on Windows. So I think I am not registering something correctly.

I know this has something to do with when the events are getting fired, but I have spend hours on trying to diagnose this behavior and have run out of ideas.

Here is where I am registering the event handlers, the complete code is BoundedTextAreaWithFeedback.

private void registerHandlers()
{
    final BoundedTextAreaWithFeedback outer = this;
    this.textArea.addChangeHandler(new ChangeHandler()
    {
        public void onChange(final ChangeEvent changeEvent)
        {
            outer.validate();
        }
    });
    this.textArea.addKeyPressHandler(new KeyPressHandler()
    {
        public void onKeyPress(final KeyPressEvent keyPressEvent)
        {
            outer.validate();
        }
    });
    this.panel.addFocusHandler(new FocusHandler()
    {
        public void onFocus(final FocusEvent focusEvent)
        {
            outer.textArea.setFocus(true);
        }
    });

    // capture paste events
    this.textArea.sinkEvents(Event.ONPASTE);
}

Here is the validate() method.

private boolean validate()
{
    final boolean isValid;
    final int len = this.textArea.getText().length();
    if (len < this.minLength)
    {
        this.status.setText("Enter at least " + this.minLength + " characters.");
        this.status.setStyleName("input-status-underflow");
        isValid = false;
    }
    else if (len > this.maxLength)
    {
        this.status.setText(this.maxLength - len + " characters remaining");
        this.status.setStyleName("input-status-overflow");
        isValid = false;
    }
    else
    {
        this.status.setText(this.maxLength - len + " characters remaining");
        this.status.setStyleName("input-status-ok");
        isValid = true;
    }
    return isValid;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:57:04+00:00Added an answer on May 20, 2026 at 9:57 am

    I just started adding every addXXXHandler() until one worked.

    this.textArea.addKeyUpHandler(new KeyUpHandler()
    {
        public void onKeyUp(final KeyUpEvent event)
        {
            outer.validate();
        }
    });
    

    Seems to have done the trick.

    Here is the working code, CTRL-V and paste from context menu also work now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use GWT-Ext library for building GUI for a webapp. I'd like to process
I have a peculiar issue here in the Spring-GWT application we are building. We
I'm building a GWT Application. But i dont want user to enter any html
I'm in a process of selecting an API for building a GWT application. The
I'm building application with GWT + GAE on my MAC. In this app i
I'm building dynamic forms in GWT, but I'm not sure how to dynamically retrieve
I'm currently building a GWT login screen and I managed to get a basic
I am building a GWT app with Spring. I am having some issues to
I am building a GWT app that uses Web SQL Local Storage ( http://dev.w3.org/html5/webdatabase/
I've been trying to learn GWT for quite a while, I want to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.