I am understanding how to handle JS events like onfocus and onblur in apache wicket. I have a simple form in which there is a textfield. "onfocus" event on this I am trying to set the textfield to a value. I have observed on running the code that onfocus is called again and again (recursively it seems). I fail to understand why and what I have done wrong. Below is the code :
HTML: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org"> <head> <title>Wicket Examples - component reference</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <form wicket:id="form"> <INPUT wicket:id="input" type="text" name="input" style="WIDTH: 800px" /> </form> Java: package com.poc.pages; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.Model; public class IndexPage extends WebPage { /** * Constructor */ public IndexPage() { Form form = new Form("form"); TextField<String> TextInput = new TextField<String>("input",Model.of("")); TextInput.add(new AjaxFormComponentUpdatingBehavior("onfocus"){ @Override protected void onUpdate(AjaxRequestTarget target) { String thisValue = this.getComponent().getDefaultModelObjectAsString(); thisValue = "ChangedNormally"; this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel"); target.add(this.getComponent()); System.out.println("onfocus"+thisValue); } }); form.add(TextInput); add(form); } } When I focus on textfield here, ChangedViaDefaultSetModel is set and on console onfocusChangedNormally gets print continuously. I fail to undertsand few things : Why does onfocus gets called again and again printing onfocusChangedNormally evertytime on console? How can I get the value of actual model and not default model. WHy does the normal value doesnot get reflected in model whereas on doing setDefaultModel() it works? Thanks For Help -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
