You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mihaela Pilon <mi...@gmail.com> on 2010/11/16 06:16:27 UTC

Form field inputs automatically cleared when "success" reached!?

Hi,

I have a problem where my form field inputs are always cleared after
my "success" event handling.

It's all fine when I can check my inputs prior to "success", such as
inside "validateForm" handler, but sometimes there is no error in
form, but is raised by service layer in form of exception, and I want
to catch it and stay on same page with error shown. Unfortunately in
that case form inputs are cleared. It seems that Tapestry assumes that
once the "success" handler is reached that everything will be fine
afterwards, whereas it doesn't have to.

How do you handle these situations folks, I'm sure this isn't something unusual?

-MP

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by niksami <ni...@fleka.me>.
Mark fields used in form with @Persist("flash") annotation, so they won't be
cleared if you catch some error during validation. These fields will be
cleared after second reload of page, and that will supply your needs I
think. If you need to stay on that page after the form is successfully
submitted, use ComponentResources in onSuccess() to clear persistent field
values.

Example:

@Persist("flash")
private String username;

@Inject
private ComponentResources _componentResources;

....

Object onSuccess() {
    ...
    _componentResources.discardPersistentFieldChanges();
   return null; //to stay on same page after success. Ignore this usage of
ComponentResources if you
                    //     redirect to another page (99% of cases).
}
 

Mihaela Pilon wrote:
> 
> Hi,
> 
> I have a problem where my form field inputs are always cleared after
> my "success" event handling.
> 
> It's all fine when I can check my inputs prior to "success", such as
> inside "validateForm" handler, but sometimes there is no error in
> form, but is raised by service layer in form of exception, and I want
> to catch it and stay on same page with error shown. Unfortunately in
> that case form inputs are cleared. It seems that Tapestry assumes that
> once the "success" handler is reached that everything will be fine
> afterwards, whereas it doesn't have to.
> 
> How do you handle these situations folks, I'm sure this isn't something
> unusual?
> 
> -MP
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Form-field-inputs-automatically-cleared-when-success-reached-tp3266860p3267019.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: Form field inputs automatically cleared when "success" reached!?

Posted by Massimo Lusetti <ml...@gmail.com>.
On Tue, Nov 16, 2010 at 4:27 PM, Vjeran Marcinko
<vj...@email.t-com.hr> wrote:

> Not sure I quite understood you, but...

Hope to be more clear...

> I don't say there is no easy workaround for this  - use ValidateForm and
> return "this", although one could argue that "validateForm" isn't the right
> name for method where one doesn't validate anything, just wants to execute
> service layer operation and catch possible exception. "success" handler
> seems as the right place for calling service logic since all form validation
> passed fine, doesn't it (error is not due to form validation, but service
> error)?

Walking these fields of discussion is almost always unproductive where
anyone can have it's own way of thought, for example, db data
constraints where belongs? Doesn't belongs to where I validate data
submitted?

> But lingering question remains why any workaround is needed for something
> that is normal in 99% of cases (having fields inputs seen again when staying
> on same page), and not having workaround for something that is unusual
> (clearing input fields when staying on same page)?

Oh well... my mileage may vary quite a lot, and others can say the
same too... I find the situation perfectly suites my needs. I've never
had the needs to stay on the same page and show the form (plus with
editable fields) after a successful form iteration...

After a successful form submission you somehow save the data and then
you have the data so there's no need to keep them up in the
ValidationTracker. Isn't it?

Cheers
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Vjeran Marcinko <vj...@email.t-com.hr>.
----- Original Message ----- 
From: "Massimo Lusetti" <ml...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Tuesday, November 16, 2010 4:11 PM
Subject: Re: Form field inputs automatically cleared when "success" 
reached!?


> On Tue, Nov 16, 2010 at 4:00 PM, Vjeran Marcinko
> <vj...@email.t-com.hr> wrote:
>
>> Long time ago this was reported on JIRA, but Howard closed the issue due 
>> to
>> some back-compatibility issues:
>> https://issues.apache.org/jira/browse/TAP5-182
>
> And there you were specifically told to us the validation event
> handler method to to the thing you need and eventually return
> something (this) bypass subsequent handler methods...
>
> I can see this as a specific case but the framework could adapt
> easily... isn't it?

Not sure I quite understood you, but...
I don't say there is no easy workaround for this  - use ValidateForm and 
return "this", although one could argue that "validateForm" isn't the right 
name for method where one doesn't validate anything, just wants to execute 
service layer operation and catch possible exception. "success" handler 
seems as the right place for calling service logic since all form validation 
passed fine, doesn't it (error is not due to form validation, but service 
error)?

But lingering question remains why any workaround is needed for something 
that is normal in 99% of cases (having fields inputs seen again when staying 
on same page), and not having workaround for something that is unusual 
(clearing input fields when staying on same page)?

-Vjeran
 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Massimo Lusetti <ml...@gmail.com>.
On Tue, Nov 16, 2010 at 4:00 PM, Vjeran Marcinko
<vj...@email.t-com.hr> wrote:

> Long time ago this was reported on JIRA, but Howard closed the issue due to
> some back-compatibility issues:
> https://issues.apache.org/jira/browse/TAP5-182

And there you were specifically told to us the validation event
handler method to to the thing you need and eventually return
something (this) bypass subsequent handler methods...

I can see this as a specific case but the framework could adapt
easily... isn't it?

Cheers
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Vjeran Marcinko <vj...@email.t-com.hr>.
----- Original Message ----- 
From: "Massimo Lusetti" <ml...@gmail.com>
Newsgroups: gmane.comp.java.tapestry.user
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Tuesday, November 16, 2010 10:30 AM
Subject: Re: Form field inputs automatically cleared when "success" 
reached!?


> On Tue, Nov 16, 2010 at 6:22 AM, Kalle Korhonen
> <ka...@gmail.com> wrote:
>
>> That's exactly the reason why I typically save and catch the errors in
>> onValidateForm but commit only in onSuccess. Purists claim it's misuse
>> of the validate event but in practice makes sense.
>
> Not at all!
> It varies between situation but in general I think is a best practice too.

Actually, I think this problem can be widen for any situation where one 
wants to stay on same page after form submit, regardless if there was 
service layer exception caught or simply because one doesn't want to 
navigate to other page.
I recon in 99% of cases, one wants field inputs to be seen again when 
staying on same page, regardless whether error occured or not. So 
ValidationTracker should not *ever* be automatically cleared. It's "flash" 
persistence strategy should clear it when going to other pages. In those 
rare cases when one wants to stay on same page and clear those field, he 
should explicitly call ValidationTracker.clear() (or hwaever it's called).

Long time ago this was reported on JIRA, but Howard closed the issue due to 
some back-compatibility issues:
https://issues.apache.org/jira/browse/TAP5-182

-Vjeran 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Massimo Lusetti <ml...@gmail.com>.
On Tue, Nov 16, 2010 at 6:22 AM, Kalle Korhonen
<ka...@gmail.com> wrote:

> That's exactly the reason why I typically save and catch the errors in
> onValidateForm but commit only in onSuccess. Purists claim it's misuse
> of the validate event but in practice makes sense.

Not at all!
It varies between situation but in general I think is a best practice too.

Cheers
-- 
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Kalle Korhonen <ka...@gmail.com>.
On Tue, Nov 16, 2010 at 11:03 AM, Howard Lewis Ship <hl...@gmail.com> wrote:
> On Mon, Nov 15, 2010 at 9:22 PM, Kalle Korhonen
> <ka...@gmail.com>wrote:
>> That's exactly the reason why I typically save and catch the errors in
>> onValidateForm but commit only in onSuccess. Purists claim it's misuse
>> of the validate event but in practice makes sense.
> Who are these purists?  That's exactly what the ValidateForm event is for.
>  It's your chance to verify the form and associated behavior as a unit prior
> to the determination of success and failure.

Right, I couldn't agree more with you - the persistence layers can
throw validation errors as well. If you must know, I'm specifically
referring to "Exception handling after violation of unique constraint"
thread, for example:
"On Fri, Sep 11, 2009 at 7:26 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> I think onValidate() is for validation, the data store should only be
> changed (or attepted to be changed) when validation succeeds and controller
> classes (business rules tier) should deal with transactions, not
> Tapestry-related code (nor any UI code). I write code following the
> three-tiers architecture and the separation of concerns philosphy strictly."

As well as the few "T5: Edit page best practice" threads and
"Exception handling + @CommitAfter" thread, see the archives.

Kalle


>> On Mon, Nov 15, 2010 at 9:16 PM, Mihaela Pilon <mi...@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > I have a problem where my form field inputs are always cleared after
>> > my "success" event handling.
>> >
>> > It's all fine when I can check my inputs prior to "success", such as
>> > inside "validateForm" handler, but sometimes there is no error in
>> > form, but is raised by service layer in form of exception, and I want
>> > to catch it and stay on same page with error shown. Unfortunately in
>> > that case form inputs are cleared. It seems that Tapestry assumes that
>> > once the "success" handler is reached that everything will be fine
>> > afterwards, whereas it doesn't have to.
>> >
>> > How do you handle these situations folks, I'm sure this isn't something
>> unusual?
>> >
>> > -MP
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > For additional commands, e-mail: users-help@tapestry.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to learn
> how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Fernando Padilla <fe...@alum.mit.edu>.
I think he meant, that he opens the database transaction in the 
validation step.. then some unknown time later, he commits it within 
success.  that does sound a bit dirty to me.

On 11/16/10 11:03 AM, Howard Lewis Ship wrote:
> On Mon, Nov 15, 2010 at 9:22 PM, Kalle Korhonen
> <ka...@gmail.com>wrote:
>
>> That's exactly the reason why I typically save and catch the errors in
>> onValidateForm but commit only in onSuccess. Purists claim it's misuse
>> of the validate event but in practice makes sense.
>>
> Who are these purists?  That's exactly what the ValidateForm event is for.
>   It's your chance to verify the form and associated behavior as a unit prior
> to the determination of success and failure.
>
>
>> Kalle
>>
>>
>> On Mon, Nov 15, 2010 at 9:16 PM, Mihaela Pilon<mi...@gmail.com>
>> wrote:
>>> Hi,
>>>
>>> I have a problem where my form field inputs are always cleared after
>>> my "success" event handling.
>>>
>>> It's all fine when I can check my inputs prior to "success", such as
>>> inside "validateForm" handler, but sometimes there is no error in
>>> form, but is raised by service layer in form of exception, and I want
>>> to catch it and stay on same page with error shown. Unfortunately in
>>> that case form inputs are cleared. It seems that Tapestry assumes that
>>> once the "success" handler is reached that everything will be fine
>>> afterwards, whereas it doesn't have to.
>>>
>>> How do you handle these situations folks, I'm sure this isn't something
>> unusual?
>>> -MP
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Form field inputs automatically cleared when "success" reached!?

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Mon, Nov 15, 2010 at 9:22 PM, Kalle Korhonen
<ka...@gmail.com>wrote:

> That's exactly the reason why I typically save and catch the errors in
> onValidateForm but commit only in onSuccess. Purists claim it's misuse
> of the validate event but in practice makes sense.
>

Who are these purists?  That's exactly what the ValidateForm event is for.
 It's your chance to verify the form and associated behavior as a unit prior
to the determination of success and failure.


>
> Kalle
>
>
> On Mon, Nov 15, 2010 at 9:16 PM, Mihaela Pilon <mi...@gmail.com>
> wrote:
> > Hi,
> >
> > I have a problem where my form field inputs are always cleared after
> > my "success" event handling.
> >
> > It's all fine when I can check my inputs prior to "success", such as
> > inside "validateForm" handler, but sometimes there is no error in
> > form, but is raised by service layer in form of exception, and I want
> > to catch it and stay on same page with error shown. Unfortunately in
> > that case form inputs are cleared. It seems that Tapestry assumes that
> > once the "success" handler is reached that everything will be fine
> > afterwards, whereas it doesn't have to.
> >
> > How do you handle these situations folks, I'm sure this isn't something
> unusual?
> >
> > -MP
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Form field inputs automatically cleared when "success" reached!?

Posted by Kalle Korhonen <ka...@gmail.com>.
That's exactly the reason why I typically save and catch the errors in
onValidateForm but commit only in onSuccess. Purists claim it's misuse
of the validate event but in practice makes sense.

Kalle


On Mon, Nov 15, 2010 at 9:16 PM, Mihaela Pilon <mi...@gmail.com> wrote:
> Hi,
>
> I have a problem where my form field inputs are always cleared after
> my "success" event handling.
>
> It's all fine when I can check my inputs prior to "success", such as
> inside "validateForm" handler, but sometimes there is no error in
> form, but is raised by service layer in form of exception, and I want
> to catch it and stay on same page with error shown. Unfortunately in
> that case form inputs are cleared. It seems that Tapestry assumes that
> once the "success" handler is reached that everything will be fine
> afterwards, whereas it doesn't have to.
>
> How do you handle these situations folks, I'm sure this isn't something unusual?
>
> -MP
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org