Wicket: so ändern Sie text des Labels auf textarea onkeyup?

Wie wechsle ich den text des Labels auf textarea onkeyup? Ich hab das versucht aber funktioniert nicht:

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") );
    }
  }

Lösung

leonidv war fast da. Der resultierende code ist:

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

Dem letzten problem wurde mir schlecht intuition über das hinzufügen von renderComponent() -, dass aus irgendeinem Grund, behalten die Bezeichnung unverändert.

Durch die Art und Weise, das Ergebnis wird dazu dienen bald als JTexy lightweight markup language sandbox.

Danke für die Hilfe!

InformationsquelleAutor Ondra Žižka | 2010-01-22

Schreibe einen Kommentar