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 564939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:49:09+00:00 2026-05-13T12:49:09+00:00

How do I change label’s text on textarea’s onkeyup? I’ve tried this but does

  • 0

How do I change label’s text on textarea’s onkeyup? I’ve tried this but does not work:

Form form;
TextArea ta;
MyLabel resultDiv;


  /**
   * Constructor that is invoked when page is invoked without a session.
   */
  public HomePage(final PageParameters parameters) {

      this.form = new Form("form");
      this.ta = new TextArea("text");
      this.resultDiv = new MyLabel("result");

      this.ta.add( new AjaxEventBehavior( "onKeyUp" ) {
        protected void onEvent( AjaxRequestTarget target ) {
          System.out.println( "Ajax!" );
          resultDiv.setText("Foobar");
          resultDiv.renderComponent();
        }
      } );


      form.add( ta );
      form.add( resultDiv );
      add( form );

  }// const

  public class MyLabel extends Label {
    private String text = "original";
    public String getText() {      return text;    }
    public void setText( String text ) {      this.text = text;    }
    public MyLabel( String id ) {
      super( id );
      this.setModel( new PropertyModel(this,"text") );
    }
  }

Solution

leonidv was almost there. The resulting code is:

Form form;
TextArea ta;
Label resultDiv = new Label( "result", new PropertyModel(this,"labelText") ){
  { setOutputMarkupId( true ); }
};

private String labelText = "original";


/**
 * Constructor that is invoked when page is invoked without a session.
 */
public HomePage(final PageParameters parameters) {

    this.form = new Form("form");

    this.ta = new TextArea("text");
    this.ta.add( new AjaxEventBehavior( "onKeyUp" ) {
      protected void onEvent( AjaxRequestTarget target ) {
        System.out.println( "Ajax!" );
        labelText = "Foobar";  // Doesn't even need get/set, which is great.
        target.addComponent( resultDiv );
        //resultDiv.renderComponent(); // WRONG!!
      }
    } );

    form.add( ta );
    form.add( resultDiv );
    add( form );

}// const

The last problem was my bad intuition about adding renderComponent() – that, for some reason, kept the label unchanged.

By the way, the result will serve soon as JTexy lightweight markup language sandbox.

Thanks for help!

  • 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-13T12:49:09+00:00Added an answer on May 13, 2026 at 12:49 pm

    If you want to update components after AJAX event, you must to do 2 things:

    1. Updatable components must have setted flag setOutputMarkupId == true;
    2. You must add this components to target onEvent method

      this.resultDiv.setMarkupOutputId(true);
      
      protected void onEvent( AjaxRequestTarget target ) {
            System.out.println( "Ajax!" );
            //resultDiv.setModel(  );
            resultDiv.setText("Foobar");
            resultDiv.renderComponent();
            target.add(resultDiv);
      }
      

    PS I don’t understand many parts of your code.

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

Sidebar

Related Questions

How can I change the width of a textarea form element if I used
The problem is that I need to change Label FontWeight and FontStyle programmatically but
Simple question. But I can't find an answer yet. How to change label line
I am trying to change a label's text by using server-side JavaScript (onclick) and
As the title suggests. I want to be able to change the label of
Is it possible to change the width of a scroll bar on a form.
Lately I had to change some code on older systems where not all of
how do I change the label No Results, when using a searchDisplayController? Regards
How do I change a label's colour (for example labelname = myLBL) programmatically? Thanks
any one know how to change the label side of ChoiceGroup or TextField.( i

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.