You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by suvojit168 <su...@gmail.com> on 2014/07/30 14:35:19 UTC
onfocus event getting called recursively in Apache wicket
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: onfocus event getting called recursively in Apache wicket
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Wed, Jul 30, 2014 at 7:35 PM, suvojit168 <su...@gmail.com> wrote:
> Hi,
>
> Thanks for replying.
>
> My requirement is to clear the textfield on onfocus (although here I was
> trying to set a string in textfield). Unless I add the component to
> ajaxtarget, how will it be updated on UI?
>
>
> Sven Meier wrote
> >>How can I get the value of actual model and not default model.
> >
> > Sorry, I don't understand that.
>
> Sorry for being vague, I wanted to understand why does doing
> *"this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel");"*
>
> change the textfield value but
> *String thisValue =
>
> this.getComponent().getDefaultModelObjectAsString();
> thisValue = "ChangedNormally";*
>
Yes. You are wrong!
thisValue is just a plain local String variable. It is not connected to the
TextField component anyhow.
By doing component.setDefaultModelObject(anything) you set the new value of
the component model object.
>
> does not? I think after all both means same here. Correct me if I am wrong.
>
> Thanks
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666807.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: onfocus event getting called recursively in Apache wicket
Posted by Martin Grigorov <mg...@apache.org>.
On Thu, Jul 31, 2014 at 11:45 AM, suvojit168 <su...@gmail.com> wrote:
> Hi Sven,
>
> Can you please make me understand why should I use JS here over wicket. I
> have read somewhere lately that onfocus in wicket has some fault (Perhaps
> in
> version 1.4. I am not sure if it has been fixed in 1.6 or not. BTW I cant
> find the source now :( ). Are you indicating the same fault in wicket as
> reason to use JS here?
>
If there is no ticket in our JIRA about it then there is no (known) problem!
> I want to avoid JS as much as possible and want to keep stuff in wicket
> mostly. I would love to leverage wicket's power.
>
> Thanks,
> Suvo
>
>
> Sven Meier wrote
> > Hi,
> >
> > you should do that with JavaScript only.
> >
> > Sven
> >
> > On 07/30/2014 07:35 PM, suvojit168 wrote:
> >> Hi,
> >>
> >> Thanks for replying.
> >>
> >> My requirement is to clear the textfield on onfocus (although here I was
> >> trying to set a string in textfield). Unless I add the component to
> >> ajaxtarget, how will it be updated on UI?
> >>
> >>
> >> Sven Meier wrote
> >>>> How can I get the value of actual model and not default model.
> >>> Sorry, I don't understand that.
> >> Sorry for being vague, I wanted to understand why does doing
> >>
> *"this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel");"*
> >>
> >> change the textfield value but
> >> *String thisValue =
> >>
> this.getComponent().getDefaultModelObjectAsString();
> >> thisValue = "ChangedNormally";*
> >>
> >> does not? I think after all both means same here. Correct me if I am
> >> wrong.
> >>
> >> Thanks
> >>
> >> --
> >> View this message in context:
> >>
> http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666807.html
> >> Sent from the Users forum mailing list archive at Nabble.com.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
>
> > users-unsubscribe@.apache
>
> >> For additional commands, e-mail:
>
> > users-help@.apache
>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
>
> > users-unsubscribe@.apache
>
> > For additional commands, e-mail:
>
> > users-help@.apache
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666823.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: onfocus event getting called recursively in Apache wicket
Posted by suvojit168 <su...@gmail.com>.
Hi Sven,
Can you please make me understand why should I use JS here over wicket. I
have read somewhere lately that onfocus in wicket has some fault (Perhaps in
version 1.4. I am not sure if it has been fixed in 1.6 or not. BTW I cant
find the source now :( ). Are you indicating the same fault in wicket as
reason to use JS here?
I want to avoid JS as much as possible and want to keep stuff in wicket
mostly. I would love to leverage wicket's power.
Thanks,
Suvo
Sven Meier wrote
> Hi,
>
> you should do that with JavaScript only.
>
> Sven
>
> On 07/30/2014 07:35 PM, suvojit168 wrote:
>> Hi,
>>
>> Thanks for replying.
>>
>> My requirement is to clear the textfield on onfocus (although here I was
>> trying to set a string in textfield). Unless I add the component to
>> ajaxtarget, how will it be updated on UI?
>>
>>
>> Sven Meier wrote
>>>> How can I get the value of actual model and not default model.
>>> Sorry, I don't understand that.
>> Sorry for being vague, I wanted to understand why does doing
>> *"this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel");"*
>>
>> change the textfield value but
>> *String thisValue =
>> this.getComponent().getDefaultModelObjectAsString();
>> thisValue = "ChangedNormally";*
>>
>> does not? I think after all both means same here. Correct me if I am
>> wrong.
>>
>> Thanks
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666807.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
> users-unsubscribe@.apache
>> For additional commands, e-mail:
> users-help@.apache
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@.apache
> For additional commands, e-mail:
> users-help@.apache
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666823.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: onfocus event getting called recursively in Apache wicket
Posted by Sven Meier <sv...@meiers.net>.
Hi,
you should do that with JavaScript only.
Sven
On 07/30/2014 07:35 PM, suvojit168 wrote:
> Hi,
>
> Thanks for replying.
>
> My requirement is to clear the textfield on onfocus (although here I was
> trying to set a string in textfield). Unless I add the component to
> ajaxtarget, how will it be updated on UI?
>
>
> Sven Meier wrote
>>> How can I get the value of actual model and not default model.
>> Sorry, I don't understand that.
> Sorry for being vague, I wanted to understand why does doing
> *"this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel");"*
>
> change the textfield value but
> *String thisValue =
> this.getComponent().getDefaultModelObjectAsString();
> thisValue = "ChangedNormally";*
>
> does not? I think after all both means same here. Correct me if I am wrong.
>
> Thanks
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666807.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: onfocus event getting called recursively in Apache wicket
Posted by suvojit168 <su...@gmail.com>.
Hi,
Thanks for replying.
My requirement is to clear the textfield on onfocus (although here I was
trying to set a string in textfield). Unless I add the component to
ajaxtarget, how will it be updated on UI?
Sven Meier wrote
>>How can I get the value of actual model and not default model.
>
> Sorry, I don't understand that.
Sorry for being vague, I wanted to understand why does doing
*"this.getComponent().setDefaultModelObject("ChangedViaDefaultSetModel");"*
change the textfield value but
*String thisValue =
this.getComponent().getDefaultModelObjectAsString();
thisValue = "ChangedNormally";*
does not? I think after all both means same here. Correct me if I am wrong.
Thanks
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/onfocus-event-getting-called-recursively-in-Apache-wicket-tp4666802p4666807.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: onfocus event getting called recursively in Apache wicket
Posted by Sven Meier <sv...@meiers.net>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org