You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoffrey Wiseman <ge...@gmail.com> on 2009/04/22 22:38:31 UTC
Ajax and Validation
I wasn't sure if Tapestry did any magic under the covers to work with
server-side validation and ajax form submits. I did a quick experiment and
it doesn't seem to:
- Create a form, give it a zone to do ajax submit.
- Create an onValidateForm method, throw a ValidationException from it.
- Load up the application. Submit the form.
- The zone gets updated, no validation messages appear.
No big surprises so far -- this is Ajax form submits and the fact that
validation isn't meant to work with it, near as I can tell. The next part,
however, worries me a little:
- Refresh the page, or go the same URL.
- The page renders as if you'd just submitted the form. The field is
populated an there's a visible error block.
- I don't have any Persist annotations here or anything, so I'm a little
disturbed that it's retaining a form value and validation state despite
that.
Am I missing something, or is this some kind of ugly edge case around ajax
and form validation?
Now you could argue that ajax form submits and validation don't belong
together, which I might agree with. I'd have to understand how Tapestry
handles graceful degradation in order to argue the point.
On a side note, I'd love to be able to throw a t:errors outside of a form in
a block and point it /to/ the form to use that to display validation
errors. (e.g. <t:block t:id="errors"><t:errors t:form="save" /></t:block>)
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: Ajax and Validation
Posted by Michael Gentry <mg...@masslight.net>.
Hi Geoffrey (and others),
Did you ever figure out a workaround for this issue? I have:
<t:zone t:id="wizard" t:update="show" id="wizard">
...
<t:block t:id="enterEmail">
<t:form t:id="inputs" t:zone="wizard">
<h3>Enter E-mail Address</h3>
<div t:type="Errors"/>
And when I record e-mail address problems in the form, the t:errors
never renders (unless I reload the page as you said). At this point,
I'll either have to add my own error message presentation or give up
on zones since they don't show the validation errors.
Thanks,
mrg
On Wed, Apr 22, 2009 at 4:38 PM, Geoffrey
Wiseman<ge...@gmail.com> wrote:
> I wasn't sure if Tapestry did any magic under the covers to work with
> server-side validation and ajax form submits. I did a quick experiment and
> it doesn't seem to:
>
> - Create a form, give it a zone to do ajax submit.
> - Create an onValidateForm method, throw a ValidationException from it.
> - Load up the application. Submit the form.
> - The zone gets updated, no validation messages appear.
>
> No big surprises so far -- this is Ajax form submits and the fact that
> validation isn't meant to work with it, near as I can tell. The next part,
> however, worries me a little:
>
> - Refresh the page, or go the same URL.
> - The page renders as if you'd just submitted the form. The field is
> populated an there's a visible error block.
> - I don't have any Persist annotations here or anything, so I'm a little
> disturbed that it's retaining a form value and validation state despite
> that.
>
> Am I missing something, or is this some kind of ugly edge case around ajax
> and form validation?
>
> Now you could argue that ajax form submits and validation don't belong
> together, which I might agree with. I'd have to understand how Tapestry
> handles graceful degradation in order to argue the point.
>
> On a side note, I'd love to be able to throw a t:errors outside of a form in
> a block and point it /to/ the form to use that to display validation
> errors. (e.g. <t:block t:id="errors"><t:errors t:form="save" /></t:block>)
>
> - Geoffrey
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Ajax and Validation
Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Wed, Apr 22, 2009 at 7:04 PM, Joost Schouten (mailing lists) <
joost_ml@jsportal.com> wrote:
> On Thu, Apr 23, 2009 at 8:38 AM, Geoffrey Wiseman
> <ge...@gmail.com> wrote:
> > I wasn't sure if Tapestry did any magic under the covers to work with
> > server-side validation and ajax form submits. I did a quick experiment
> and
> > it doesn't seem to:
> >
> > - Create a form, give it a zone to do ajax submit.
> > - Create an onValidateForm method, throw a ValidationException from it.
> > - Load up the application. Submit the form.
> > - The zone gets updated, no validation messages appear.
>
> I use validation and ajax a lot and it works (quite) well for me. I
> just replicated what you described and it works. I assume you might
> not have the <t:errors/> component in the block that gets loaded in
> the zone, nor record the error to one of the Fields.
That's correct, t:errors isn't in the zone. The zone isn't in the form. It
possibly could be, I hadn't thought about that option.
> This way, no
> visual feedback is given. If your setup doesn't work well with placing
> the <t:errors/> in the block that gets reloaded, you could consider
> placing it in a zone by itself and update multiple zones on the one
> form submit by returning a MultiZoneUpdate from your
> EventConstants.SUCCESS action. (haven't tried this btw)
>
That's a 5.1.X option, IIRC; I'm still on 5.0.x, but it's good to know that
a zone containing the errors in the form would render as desired. Now if I
could get an errors component to link to a form it's not in, I'd have even
more flex. That said, most of the above I can live with, it's really the
weird error persistence thing that was worrisome to me.
- Geoffrey
--
Geoffrey Wiseman
http://www.geoffreywiseman.ca/
Re: Ajax and Validation
Posted by "Joost Schouten (mailing lists)" <jo...@jsportal.com>.
On Thu, Apr 23, 2009 at 8:38 AM, Geoffrey Wiseman
<ge...@gmail.com> wrote:
> I wasn't sure if Tapestry did any magic under the covers to work with
> server-side validation and ajax form submits. I did a quick experiment and
> it doesn't seem to:
>
> - Create a form, give it a zone to do ajax submit.
> - Create an onValidateForm method, throw a ValidationException from it.
> - Load up the application. Submit the form.
> - The zone gets updated, no validation messages appear.
I use validation and ajax a lot and it works (quite) well for me. I
just replicated what you described and it works. I assume you might
not have the <t:errors/> component in the block that gets loaded in
the zone, nor record the error to one of the Fields. This way, no
visual feedback is given. If your setup doesn't work well with placing
the <t:errors/> in the block that gets reloaded, you could consider
placing it in a zone by itself and update multiple zones on the one
form submit by returning a MultiZoneUpdate from your
EventConstants.SUCCESS action. (haven't tried this btw)
>
> No big surprises so far -- this is Ajax form submits and the fact that
> validation isn't meant to work with it, near as I can tell. The next part,
> however, worries me a little:
>
> - Refresh the page, or go the same URL.
> - The page renders as if you'd just submitted the form. The field is
> populated an there's a visible error block.
> - I don't have any Persist annotations here or anything, so I'm a little
> disturbed that it's retaining a form value and validation state despite
> that.
>
> Am I missing something, or is this some kind of ugly edge case around ajax
> and form validation?
>
> Now you could argue that ajax form submits and validation don't belong
> together, which I might agree with. I'd have to understand how Tapestry
> handles graceful degradation in order to argue the point.
>
> On a side note, I'd love to be able to throw a t:errors outside of a form in
> a block and point it /to/ the form to use that to display validation
> errors. (e.g. <t:block t:id="errors"><t:errors t:form="save" /></t:block>)
This does seem strange. My guess is that the ValidationTracker uses
some sort of flash persist that works well on a page request but might
not on an Ajax request because it does not use an redirect. Maybe one
of the commiters can comment on this?
>
> - Geoffrey
Cheers,
Joost
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
partial form update
Posted by Jorge Saridis <js...@gmail.com>.
Hi, is there a way to partially update a form from an action link?
Thanks in advance
Jorge
Re: Ajax and Validation
Posted by Dmitry Gusev <dm...@gmail.com>.
I know this thread is too old, but I still have this same issue in T5.3.7.
Since @PageDetached is no longer works, here is how I managed to fix this
for my form:
@Inject private Heartbeat heartbeat;
public void onSubmit()
{
if (request.isXHR())
{
// ...
ajaxResponseRenderer.addCallback(new JavaScriptCallback()
{
@Override
public void run(JavaScriptSupport javascriptSupport)
{
// ...
heartbeat.defer(new Runnable()
{
@Override
public void run()
{
form.clearErrors();
}
});
}
});
}
}
On Mon, Jun 13, 2011 at 10:07 PM, Kartweel <rh...@exemail.com.au> wrote:
> It still gave me issues when submitting a form with an error then
> submitting
> it valid, then it would bring up the old values and clobber the real values
> (after saving I default back to different data in the form).
>
> So I ammended it to
>
>
> @PageDetached
> void clearValidationTracker() {
> if (request.isXHR()) {
> if (workItemsForm.getDefaultTracker() != null)
> workItemsForm.getDefaultTracker().clear();
> workItemsForm.setDefaultTracker(null);
> }
> }
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Ajax-and-Validation-tp2431706p4485240.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Dmitry Gusev
AnjLab Team
http://anjlab.com
Re: Ajax and Validation
Posted by Kartweel <rh...@exemail.com.au>.
It still gave me issues when submitting a form with an error then submitting
it valid, then it would bring up the old values and clobber the real values
(after saving I default back to different data in the form).
So I ammended it to
@PageDetached
void clearValidationTracker() {
if (request.isXHR()) {
if (workItemsForm.getDefaultTracker() != null)
workItemsForm.getDefaultTracker().clear();
workItemsForm.setDefaultTracker(null);
}
}
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Ajax-and-Validation-tp2431706p4485240.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Ajax and Validation
Posted by Kartweel <rh...@exemail.com.au>.
Hi,
I've had major issues with this because the ValidationTracker also reloads
old field values which in a non-ajax scenario is great, but in an ajax
scenario has caused it to clobber the proper field values. It has caused
many headaches and I think it really should be handled [better] by default
in tapestry.
I think I just came across a simple solution to the issue (that i was
specifically having anyway)
@PageDetached
void clearValidationTracker() {
if (request.isXHR()) {
if (form.getDefaultTracker() != null) form.getDefaultTracker().clear();
}
}
In early testing it seems to do what I want.
I also wrote a dummy validation tracker which doesn't persist. But it means
there is no fallback on non-ajax (which was fine for me because my objects
were persisted anyway).
Side note: I've done quite a bit of Ajax and forms in tapestry and found in
general they are nasty together. Almost to the point where I want to dump
tapestry and just code it with javascript and something a lot dumber on the
server side. Then forms and loops and ajax and wowzers!.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Ajax-and-Validation-tp2431706p4485141.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Ajax and Validation
Posted by raulmt <ra...@gmail.com>.
Thiago, I'm not saying to change the behaviour of the flash persistence. What
I mean is to change the way the Form uses this. For example, the Form could
have two properties: one with @Persist(PersistenceConstants.FLASH) and one
without it, and access the correct one through a private method. If the
request is a traditional request, then this method should return the value
holded by the persistent property, but if the request is an Ajax one, then
this method should return a ValidationTracker saved in the property without
persistence.
If I didn't explain this well enough please tell me (I'm not a native
english speaker).
Regards,
Raul.
--
View this message in context: http://tapestry-users.832.n2.nabble.com/Ajax-and-Validation-tp2678846p5860647.html
Sent from the Tapestry Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Ajax and Validation
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Changing the current behavior of the flash persistence can lead to many
hard-to-detect backward compatibility problems. I think a good solution
for this specific scenario is to set the message property to null in a
@PageDetached method.
Maybe a better solution is to create other persistence strategy similar to
flash which clears the info from the session after a request is finished.
On Tue, 21 Dec 2010 18:46:43 -0200, raulmt <ra...@gmail.com> wrote:
>
> Today I found the same problem: persist flash doesn't behave well for an
> Ajax
> request, because the error can be shown two times if you refresh the page
> (first one with the form ajax response and second one if you refresh the
> page). Maybe when processing the request, if it is an Ajax request, the
> validation tracker should not be saved in a persist flash field but in a
> regular field?
>
> If any commiter agrees with this, could I file an issue about this?
>
> Regards,
> Raul.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Ajax and Validation
Posted by raulmt <ra...@gmail.com>.
Today I found the same problem: persist flash doesn't behave well for an Ajax
request, because the error can be shown two times if you refresh the page
(first one with the form ajax response and second one if you refresh the
page). Maybe when processing the request, if it is an Ajax request, the
validation tracker should not be saved in a persist flash field but in a
regular field?
If any commiter agrees with this, could I file an issue about this?
Regards,
Raul.
--
View this message in context: http://tapestry-users.832.n2.nabble.com/Ajax-and-Validation-tp2678846p5855924.html
Sent from the Tapestry Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org