Hi,

> target.add(this.getComponent());

Wicket will refocus the textField after replacing the markup tag.

>How can I get the value of actual model and not default model.

Sorry, I don't understand that.

Regards
Sven

On 07/30/2014 02:35 PM, suvojit168 wrote:
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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to