How to change label text to textarea onkeyup? I tried this but it does not work:
Form form; TextArea ta; MyLabel resultDiv; 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 ); }
Decision
leonidv was almost there. Received code:
Form form; TextArea ta; Label resultDiv = new Label( "result", new PropertyModel(this,"labelText") ){ { setOutputMarkupId( true ); } }; private String labelText = "original"; 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";
The last problem was my bad intuition about adding renderComponent() , which for some reason kept the label intact.
By the way, the result will soon look like an isolated JTexy sandbox .
Thanks for the help!
source share