You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Quoin Developers <qu...@gmail.com> on 2006/07/03 23:30:58 UTC

Re: [CForms] Load/Save model events never send?

Hello Carsten,

I think that I've run into a problem with the change to Form. I used
to be able to do something like this in my flowscript

while (!done) {
    form.load(model);
    form.showForm("formTemplate");
    form.save(model);
}

Now, if I do this I get an exception "Cannot load form in phase
ProcessingPhase[Save model=3]" thrown from the
informStartLoadingModel() callback method.

Perhaps the phase should be set back to loading in
informEndSavingModel() (as the comment suggests), or perhaps the form
should be able to be in a lax processing phase enforcement mode.

The basic question - what are we trying to protect from by enforcing
the particular ProcessingPhase lifecycle?

Regards,
Eric Meyer

Re: [CForms] Load/Save model events never send?

Posted by Carsten Ziegeler <cz...@apache.org>.
I removed the phase checks for load and save.

Carsten

Sylvain Wallez wrote:
> Carsten Ziegeler wrote:
>> Giacomo Pati wrote:
>>
>>   
>>> Will this enable to try to store something like "abc" into a integer
>>> widget/model (which obviously would raise an Exception). If this would
>>> be possible I would certainly be against allowing 
>>> unvalidated/invalid-state saves.
>>>     
>> I don't know :) I guess it depends, if your model is using an int, I
>> guess you will get an exception. But if your form model is using an int
>> datatype but your data model is using a string (for whatever reason)
>> this might work. It also might work if you're binding to xml. But all
>> these are just guesses.
>>
>> Now, we could argue that if someone explicitly calls save() he should
>> have ensured beforehand that his data is valid.
>>   
> 
> +1.
> 
> CForms makes sure in all places that any data returned to the
> application to be valid, and returns null otherwise (with a validation
> error being set). This therefore completely shields the application from
> buggy data, which simplifies application development and avoids bugs and
> to some extend rogue data injection.
> 
> However some people have some use cases where they want to be able to
> save a form in a "draft" state, even if it's invalid. In this context,
> "saving" should'nt considered IMO to be the same as the form's save
> operation, as the form data can be not only semantically invalid (i.e.
> validators fail), but also syntactically invalid (i.e. a "abc" for an
> integer). Invalid syntax means the form's binding more than likely to
> fail to save the form (invalid bean property types).
> 
> Saving as draft therefore means saving the form values as plain text and
> restoring them as such, just as if they where read from the request.
> This is however not possible today because of the lack of the needed
> entry points in widgets. This can be solved though if people really
> needed with a couple of setStringValue()/getStringValue() methods.
> 
> Sylvain
> 


-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [CForms] Load/Save model events never send?

Posted by Sylvain Wallez <sy...@apache.org>.
Carsten Ziegeler wrote:
> Giacomo Pati wrote:
>
>   
>> Will this enable to try to store something like "abc" into a integer
>> widget/model (which obviously would raise an Exception). If this would
>> be possible I would certainly be against allowing 
>> unvalidated/invalid-state saves.
>>     
> I don't know :) I guess it depends, if your model is using an int, I
> guess you will get an exception. But if your form model is using an int
> datatype but your data model is using a string (for whatever reason)
> this might work. It also might work if you're binding to xml. But all
> these are just guesses.
>
> Now, we could argue that if someone explicitly calls save() he should
> have ensured beforehand that his data is valid.
>   

+1.

CForms makes sure in all places that any data returned to the
application to be valid, and returns null otherwise (with a validation
error being set). This therefore completely shields the application from
buggy data, which simplifies application development and avoids bugs and
to some extend rogue data injection.

However some people have some use cases where they want to be able to
save a form in a "draft" state, even if it's invalid. In this context,
"saving" should'nt considered IMO to be the same as the form's save
operation, as the form data can be not only semantically invalid (i.e.
validators fail), but also syntactically invalid (i.e. a "abc" for an
integer). Invalid syntax means the form's binding more than likely to
fail to save the form (invalid bean property types).

Saving as draft therefore means saving the form values as plain text and
restoring them as such, just as if they where read from the request.
This is however not possible today because of the lack of the needed
entry points in widgets. This can be solved though if people really
needed with a couple of setStringValue()/getStringValue() methods.

Sylvain

-- 
Sylvain Wallez - http://bluxte.net


Re: [CForms] Load/Save model events never send?

Posted by Carsten Ziegeler <cz...@apache.org>.
Giacomo Pati wrote:

> 
> Will this enable to try to store something like "abc" into a integer
> widget/model (which obviously would raise an Exception). If this would
> be possible I would certainly be against allowing 
> unvalidated/invalid-state saves.
> 
I don't know :) I guess it depends, if your model is using an int, I
guess you will get an exception. But if your form model is using an int
datatype but your data model is using a string (for whatever reason)
this might work. It also might work if you're binding to xml. But all
these are just guesses.

Now, we could argue that if someone explicitly calls save() he should
have ensured beforehand that his data is valid.

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [CForms] Load/Save model events never send?

Posted by Giacomo Pati <gi...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 6 Jul 2006, Carsten Ziegeler wrote:

> Date: Thu, 06 Jul 2006 08:32:19 +0200
> From: Carsten Ziegeler <cz...@apache.org>
> Reply-To: dev@cocoon.apache.org
> To: dev@cocoon.apache.org
> Subject: Re: [CForms] Load/Save model events never send?
> 
> Quoin Developers wrote:
>> Actually, it appears that I can save from an action handler - but it's
>> a little tricky and probably not the recommended way (calling validate
>> on the Form from the action handler).
>>
>> form.form.validate()
>> if (form.form.isValid()) {
>> form.save(facade);
>> facade.save();
>> form.getChild("contentMessages").addMessage(new I18nMessage('saved',
>> 'application'));
>> }
>>
> Uh, that's ugly. Now my intention with the phase checking for save was
> that you can only save if the form is valid which imho makes sense.
> Saving an invalid form can lead to unpredictable situations I guess.
>
> Now, I would be interested in other opinions. Should we remove these
> checks or not?

Will this enable to try to store something like "abc" into a integer
widget/model (which obviously would raise an Exception). If this would
be possible I would certainly be against allowing 
unvalidated/invalid-state saves.

- -- 
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)

iD8DBQFErMMYLNdJvZjjVZARAqkXAKDn8Hk5P1WYImgalr4JfobFwYUp7QCbBgVe
GHLni3NsKiyKJPDBlaXQM74=
=GmRq
-----END PGP SIGNATURE-----

Re: [CForms] Load/Save model events never send?

Posted by Carsten Ziegeler <cz...@apache.org>.
Quoin Developers wrote:
> Actually, it appears that I can save from an action handler - but it's
> a little tricky and probably not the recommended way (calling validate
> on the Form from the action handler).
> 
> form.form.validate()
> if (form.form.isValid()) {
> form.save(facade);
> facade.save();
> form.getChild("contentMessages").addMessage(new I18nMessage('saved',
> 'application'));
> }
> 
Uh, that's ugly. Now my intention with the phase checking for save was
that you can only save if the form is valid which imho makes sense.
Saving an invalid form can lead to unpredictable situations I guess.

Now, I would be interested in other opinions. Should we remove these
checks or not?

Carsten

-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: [CForms] Load/Save model events never send?

Posted by Quoin Developers <qu...@gmail.com>.
Actually, it appears that I can save from an action handler - but it's
a little tricky and probably not the recommended way (calling validate
on the Form from the action handler).

form.form.validate()
if (form.form.isValid()) {
form.save(facade);
facade.save();
form.getChild("contentMessages").addMessage(new I18nMessage('saved',
'application'));
}

Regards,
Eric Meyer

Re: [CForms] Load/Save model events never send?

Posted by Quoin Developers <qu...@gmail.com>.
Hi Carsten,

Thanks for the change. I'm glad to be able to use a loop in my flow again.

A similar issue arises when trying to process form actions. Say for
example, that I want to do a validation and save in an handler - I
cannot. Why might I want to do this? I'm trying to stay in Ajax mode
as much as possible for a fast and friendly user experience. I'd
propose that a form be able to be run in lax mode, and not perform the
various lifecycle checks - I keep tripping on them. That's why I was
asking what we're trying to protect. If the cforms framework won't get
into an invalid state, then users should be able to load/validate/save
as necessary without doing a full page reload.

Regards,
Eric Meyer

Re: [CForms] Load/Save model events never send?

Posted by Carsten Ziegeler <cz...@apache.org>.
Quoin Developers wrote:
> Hello Carsten,
> 
> I think that I've run into a problem with the change to Form. I used
> to be able to do something like this in my flowscript
> 
> while (!done) {
>     form.load(model);
>     form.showForm("formTemplate");
>     form.save(model);
> }
> 
> Now, if I do this I get an exception "Cannot load form in phase
> ProcessingPhase[Save model=3]" thrown from the
> informStartLoadingModel() callback method.
> 
> Perhaps the phase should be set back to loading in
> informEndSavingModel() (as the comment suggests), or perhaps the form
> should be able to be in a lax processing phase enforcement mode.
> 
Yepp, I agree. I will change that.

> The basic question - what are we trying to protect from by enforcing
> the particular ProcessingPhase lifecycle?
>
Good question :) I think this is more or less an internal consistency
check which means is the api used in the correct order.

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/