You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Federico Fanton <ff...@ibc.it> on 2008/02/18 15:16:21 UTC
AJAX validation and multiple requests
Hi everyone!
I'm having a little problem..
I have an Ajax "editable table" made with rows of custom components similar to AjaxEditableLabel, that while in "edit mode" use a behavior like this one:
protected class EditorBehavior extends AbstractDefaultAjaxBehavior{
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
String js="{wicketAjaxGet('" + getCallbackUrl() + "&'+this.name+'='+wicketEncode(this.value)); return false;}";
tag.put("onblur", js);
}
@Override
protected void respond(AjaxRequestTarget target) {
FormComponent c = (FormComponent) getEditorComponent();
c.processInput();
if(c.hasErrorMessage()){
Serializable msg = c.getFeedbackMessage().getMessage();
Util.showAlert(target, c, msg.toString());
}
}
}
(Util.showAlert adds to the component a behavior that shows an alert)
Everything works fine, but I need to add another behavior to intercept when the user presses Enter (bound to onkeyup), so that I can validate the row as a whole.
When I press enter, two requests are fired: one for onblur and one for onkeyup. My problem is that even if the onblur request finds an error during validation (and shows the corresponding alert), the second request has no way to know that, since feedback messages are cleaned up at the end of each request..
Any hint on how I could handle this? Should I put a flag somewhere? Or maybe there's a way to stop the second request when my EditorBehavior finds a validation error?
Many thanks for your time!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AJAX validation and multiple requests
Posted by Federico Fanton <ff...@ibc.it>.
On Mon, 18 Feb 2008 09:57:18 -0800
"Igor Vaynberg" <ig...@gmail.com> wrote:
> one way would be to keep a boolean somewhere that marks if the
> component is valid or not... but if i were you i would figure out why
> the two requests are fired and how to avoid it. can it be that your
> enter key handler does not return false as the last thing and so
> doesnt cancel browser's processing of enter key?
D'oh! You're right, there *IS* something fishy here.. In my key handler I call this.blur() to ensure that the field's processInput() gets called (to update the model).. So I am the one doing the double call, whoops ^^;
Maybe I could stop the "enter" processing from Javascript if I could figure out the outcome of serverside validation.. Is there a way to do this? I could try some document.validationflag perhaps..?
Again, many thanks for your time!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AJAX validation and multiple requests
Posted by Igor Vaynberg <ig...@gmail.com>.
one way would be to keep a boolean somewhere that marks if the
component is valid or not...but if i were you i would figure out why
the two requests are fired and how to avoid it. can it be that your
enter key handler does not return false as the last thing and so
doesnt cancel browser's processing of enter key?
-igor
On Feb 18, 2008 6:16 AM, Federico Fanton <ff...@ibc.it> wrote:
> Hi everyone!
> I'm having a little problem..
> I have an Ajax "editable table" made with rows of custom components similar to AjaxEditableLabel, that while in "edit mode" use a behavior like this one:
>
> protected class EditorBehavior extends AbstractDefaultAjaxBehavior{
> @Override
> protected void onComponentTag(ComponentTag tag) {
> super.onComponentTag(tag);
> String js="{wicketAjaxGet('" + getCallbackUrl() + "&'+this.name+'='+wicketEncode(this.value)); return false;}";
> tag.put("onblur", js);
> }
>
> @Override
> protected void respond(AjaxRequestTarget target) {
> FormComponent c = (FormComponent) getEditorComponent();
> c.processInput();
> if(c.hasErrorMessage()){
> Serializable msg = c.getFeedbackMessage().getMessage();
> Util.showAlert(target, c, msg.toString());
> }
> }
> }
>
>
> (Util.showAlert adds to the component a behavior that shows an alert)
>
> Everything works fine, but I need to add another behavior to intercept when the user presses Enter (bound to onkeyup), so that I can validate the row as a whole.
> When I press enter, two requests are fired: one for onblur and one for onkeyup. My problem is that even if the onblur request finds an error during validation (and shows the corresponding alert), the second request has no way to know that, since feedback messages are cleaned up at the end of each request..
> Any hint on how I could handle this? Should I put a flag somewhere? Or maybe there's a way to stop the second request when my EditorBehavior finds a validation error?
>
> Many thanks for your time!
>
>
> ---------------------------------------------------------------------
> 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: AJAX validation and multiple requests
Posted by Federico Fanton <ff...@ibc.it>.
On Wed, 20 Feb 2008 08:42:14 +0200
Timo Rantalaiho <Ti...@ri.fi> wrote:
> I think that we just stored the Component instances in that
> case, thogh you should be wary with that and especially with
> a repeater it might get difficult.
>
> A more dynamic way might be to use a marker interface for the
> relevant components and always check their states with a
> visitor. There again you should be careful with the repeater.
> However, for your form handling to work at all I suppose
> that the repeater items must not be recreated until the form
> is submitted or canceled anyway.
Nice idea! Many thanks for your help :)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AJAX validation and multiple requests
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 19 Feb 2008, Federico Fanton wrote:
> I see.. I'm trying this way too (alongside the Javascript one that
> Igor Vaynberg pointed out), so I have a Map that maps every component
> to its state, but I have a doubt.. How do you identify uniquely a
> Component? I can't use getId() since I'm inside a repeater and every
> component has the same id.. Right now I'm using getPath() and it works
> quite well, but I don't know if it's the right choice, since I'm
> refreshing the table with Ajax.. Do you store the component itself?
I think that we just stored the Component instances in that
case, thogh you should be wary with that and especially with
a repeater it might get difficult.
A more dynamic way might be to use a marker interface for the
relevant components and always check their states with a
visitor. There again you should be careful with the repeater.
However, for your form handling to work at all I suppose
that the repeater items must not be recreated until the form
is submitted or canceled anyway.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AJAX validation and multiple requests
Posted by Federico Fanton <ff...@ibc.it>.
On Tue, 19 Feb 2008 06:49:04 +0200
Timo Rantalaiho <Ti...@ri.fi> wrote:
> We have done something similar with OnChangeAjaxBehavior and
> keeping in some component or validator the state of
> validities of each FormComponent. When everything is valid,
> the whole form can be submitted.
I see.. I'm trying this way too (alongside the Javascript one that Igor Vaynberg pointed out), so I have a Map that maps every component to its state, but I have a doubt.. How do you identify uniquely a Component? I can't use getId() since I'm inside a repeater and every component has the same id.. Right now I'm using getPath() and it works quite well, but I don't know if it's the right choice, since I'm refreshing the table with Ajax.. Do you store the component itself?
Thanks for your time!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AJAX validation and multiple requests
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 18 Feb 2008, Federico Fanton wrote:
> I have an Ajax "editable table" made with rows of custom components
> similar to AjaxEditableLabel, that while in "edit mode" use a behavior
...
> Any hint on how I could handle this? Should I put a flag somewhere? Or
> maybe there's a way to stop the second request when my EditorBehavior
> finds a validation error?
We have done something similar with OnChangeAjaxBehavior and
keeping in some component or validator the state of
validities of each FormComponent. When everything is valid,
the whole form can be submitted.
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org