You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Reinhard Poetz <re...@apache.org> on 2004/11/12 21:56:34 UTC

CForms Wizards

Sylvain Wallez wrote:
> Sylvain Wallez wrote:
> 
>>
>> Sorry to rain on the party, but the new widget state stuff in CForms 
>> should make building multi-page forms a piece of cake.
>>
>> Off writing an example....
> 
> 
> 
> Done, I wrote my first wizard with CForms :-)
> 
> Please update branch 2.1.x and point your browser to 
> http://localhost:8888/forms-samples/do-multipage.flow
> 
> Enjoy!

Great, thanks for the example! One question: IIUC the wizard is driven by the 
widget states and the event handling mechanism. This may solve many use cases 
but would it be possible to control which part of the form is shown by the 
controller (flowscript) which would bring some more flexibility (mix in 
non-forms pages, jump to different sub-pages)?

[some pseudocode ...]
var myFlow() {
   var form = new Form("myForm");
   form.load(myBean);
   form.showSubForm("myPipeline", "../page1");
   cocoon.sendPageAndWait("showAnotherPage");
   form.showSubForm("myPipeline", "../page");
   form.save(myBean);
}

And while writing this, another question came up: What's the best way to deal 
with validation errors? example: On page 2 the users enters something that 
wouldn't let page 1 validate any more. Can we handle this?

-- 
Reinhard

Re: CForms Wizards

Posted by Sylvain Wallez <sy...@apache.org>.
Sylvain Wallez wrote:

> That could be something like:
>
> function validateWizard() {
>  currentPage.setState(WidgetState.INVISIBLE); // another one may be 
> chosen below
>  for (page in pageList) {
>    page.setState(WidgetState.ACTIVE);
>    if (page.validate()) {
>      page.setState(WidgetState.INVISIBLE);
>    } else {
>      return false; // validation failed
>    }
>  }


return true; // all pages validated

> }


Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: CForms Wizards

Posted by Daniel Fagerstrom <da...@nada.kth.se>.
Sylvain Wallez wrote:

> Daniel Fagerstrom wrote:
>
>> Sylvain Wallez wrote:
>>
>>> Daniel Fagerstrom wrote:
>>
<snip/>

>> Sure, IMO, you should always do a complete validation of _all_ 
>> widgets before binding your form model to business data. There is the 
>> same problem with widget states, you can have faulty event logic so 
>> that you happens to hide some subtree during all states in the 
>> filling in of the multi form.
>
> Sure, but forgetting a whole subform within the event handling is less 
> likely to happen than forgetting a single widget in the template.

The complete validation will let you know if there is a forgotten field.

> Furthermore, we can automate the subform navigation and validation, 
> not only using <fd:wizard-action> but also using a new <fd:wizard> 
> container that would automatically iterate among its children (which 
> are likely to be <fd:struct> themselves).

Might be. The important question is IMO how to separate the different 
concern areas in multi page forms. My view is that:

* What you want to show in each sub form is a view concern and should be 
handled of the view layer e.g. JXTG with taglib.

* The control of the sub form flow is a control concern, and should be 
handled by the control layer, i.e. flowscripts.

* The model is responsible for the data structure and validation. In my 
view the widget hierarchy should mainly be responsible for model concerns.

I'm of course aware of that there are gray areas where it is hard or 
maybe impractical to place a functionality in M, V or C. But I find it 
hard to be entusiastic about evolving the form definition to a mix of M, 
V and C concerns.

>> So, partial validation is used after each sub form in a wizard to 
>> give immediate feedback. Then complete validation is done before 
>> using the data. This is IMO the only safe option.
>
> Exactly. But with template-driven wizard, you don't know where to go 
> back if validation fails, whereas with definition-driven wizard, we 
> simply redisplay the first invalid subcontainer. Or will you keep the 
> list of used widgets with each step to find where a widget was firstly 
> used?

You should never be alowed to pass an invalid sub form, you can go 
backwards from it not forward. Or are you thinking about some 
backtracking engine where the user fill in a value in sub form 10 that 
not is consistent with something on sub form 2 that makes sub form 2 
redisplayed and then the user have to try to go through the sub forms 
again. In that case: to much magic for my taste.

>>> Also, this behaviour only validates terminal widgets and no 
>>> container widgets, which may carry some additional semantic checks 
>>> like row uniqueness in a repeater.
>>
>> I'm aware of that as you can see in the bugzilla comment, and have 
>> not thought that much about of it yet. One possibillity could be to 
>> let value change "bubble" and let the container validators trigger on 
>> child events. Any other ideas? I have not used container validators 
>> yet, so I don't know that much about the use cases.
>
> The current behaviour is recursive depth-first validation, i.e. a 
> container triggers its own validators if all of its children are 
> valid. I'm not sure bubbling could do the trick, as validation is 
> handled separately from value-changed events, and we have to know 
> where to stop bubbling. Bubbling up to the Form is likely not to work, 
> as validation will fail on required fields that weren't in the template.

What I mean is that container validation is trigered by validation event 
bubling. If you introduce container level bubling you must of course 
design your UI so that you are able to fill in the fields within the 
container and see the validation error in the same screen.
 
<snip/>

>> If we can find a good solution of the parent validation problem, it 
>> is rather usefull as we only need to tell about what widgets that we 
>> want to validate once, in the view. Furthermore, even if I have no 
>> immediate need for that, Jonas has shown that it makes it safe to use 
>> a form frame work without having a form model in between the view and 
>> the "business data".
>
> Uh, no form model and still safe? I missed that...

Yes, and you can do more cool things. In Chiba they use an adapter in 
the view that replaces the XPaths in the HTML output from the view with 
some kind of  random identifyers and register the mapping in a lookup 
table, that is used in the request processor. In this way you have no 
info about the model at all in what you send to the browser.

>>> Furthermore, flowscript back-button magic implies that we can only 
>>> navigate back to the previous screen, and not in an arbitrary screen 
>>> in the sequence.
>>
>> I implemented it in that way because I didn't had any use cases for 
>> something more complicated. But you can send a "go back" message 
>> together with a web continuation id to the form handler, by using 
>> that the form handler can first save the current form data and then 
>> jumping to any previous continuation. I'll explain the details in the 
>> above promised "back-button magic" RT.
>
> Things I don't like in this back-button magic:
> - not all forms are wizard, rather the contrary. So having the wizard 
> engine plugged in deep in CForms doesn't seem good to mee.

It will not disturb you if you don't use it.

> - it's magic, meaning the fact that the user can go back is even not 
> apparent in the flowscript.

We can add pluggable event handlers in the form handler so that the user 
can plug in other control flow events.

> - it is limited to CForms only, meaning if other pages are placed 
> inbetween (regular pages, other form handling, etc), they cannot 
> participate in the wizard navigation.

In the implementation I provided, it should be possible AFAIK.

> We had such a discussion one year ago and at that time I proposed a 
> wizard API [1] that makes use of bookmarks and PageLocal (that did not 
> existed at that time). Such a wizard API would make the fact that a 
> wizard-style interaction is setup explicit in the flowscript, without 
> requiring much more coding, especially if we integrate CForms in the 
> wizard API (rather than putting wizards in CForms).

<snip what="example"/>

> This approach allows to use wizard-style navigation with any kind of 
> page, and not only forms. And if we want to go further, we could even 
> make wizards a built-in feature of flowscript, i.e. add some methods 
> to the "cocoon" object such as:
> - cocoon.startWizard()
> - cocoon.wizardStep(name)
> - cocoon.finishWizard() // to invalidate all continuations in a wizard
>
> The backwards navigation could then be handled automatically by the 
> sendPageAndWait() method. Yes, that would be magic as you'll have 
> nothing special to write, except "cocoon.startWizard()", which 
> implictely says "let's start the magic, I know it will happen from now 
> on".

An excelent idea, I will give it a look. I would also prefer to have 
some kind of high level library for different flow cases. The low level 
coding with continuations is far to complicated and error proon. 
Continuations are like gotos on steroids. They are excelent for 
implementing high level control structures, but the user should not need 
to know about them or use them.

<snip/>

>> Either you decide what should be shown together in the view or in the 
>> model. You get <jx:if> (or separate templates), in the first case and 
>> fd:structs in the second. IMHO it is better to code view aspects, 
>> like what should be shown in the same sub view, in the view than in 
>> the model. It will be easier to reuse the model for several views, 
>> e.g. specialist view (one screen), wizard view and pda wizard view, 
>> if you don't put the view groupings in the model.
>
> Mmmh... I agree and disagree at the same time :-)
>
> The various widgets that will be presented in a multi-page navigation 
> will be grouped by their relations, i.e. a page will show a consistent 
> set of related data. And when displaying the same data in a single 
> page, it's very likely that the same grouping will be used to lay out 
> the page, using e.g. <fieldset> elements.
>
> In that case, the difference between the multi-page and single-page 
> templates will be that only one of these groups will be visible a one 
> time in the multi-page template.

Grouping of data is a good thing. But it is not obvious how to create a 
hierachic grouping of the data for two different wizards in such away 
that you get one group per sub form.

<snip/>

>> :) So we booth belive that multi chanel wizards mainly should affect 
>> the view. But you want AFAIU to have event based flow control in the 
>> model and I prefer to have flowscript based flow control.
>
> The event-driven model allows to have the *exact same* flowscript 
> whether the form is displayed in a single page or across multiple 
> pages. This is important in a multi-channel application as, although 
> the view will be different, the application logic should be the same 
> whatever kind of browser the user has.

Flowscripts where introduced in Cocoon for describing page flow so you 
are not supposed to reuse the part of your flowscript that describe the 
flow as that happen to be _the description_ of the page flow.

<snip/>

>> A problem with coding where we are in the wizard, booth as a widget 
>> state and a flowscript state (i.e. where we are in the form handling 
>> loop), is that previous continuations might get inconsistent. What 
>> happens if the user happens to use the browser back button in a 
>> widget state based wizard e.g.
>
> Using a single continuation within the form.showForm loop (which would 
> therefore no more be formally a loop) may be a way to handle this.

Tried that in my form.showForm loop, (that is implemented that way), and 
the browser backbutton behaviour is still flawed.

/Daniel


Re: CForms Wizards

Posted by Sylvain Wallez <sy...@apache.org>.
Daniel Fagerstrom wrote:

> Sylvain Wallez wrote:
>
>> Daniel Fagerstrom wrote:
>
> <snip/>
>
>>> Take a look at 
>>> http://issues.apache.org/bugzilla/show_bug.cgi?id=32169 where I have 
>>> enhanced work of Jonas Ekstedt so that one can do the kind of things 
>>> you asked for in the section about multi page forms in 
>>> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106672364131946&w=2.
>>>
>>> So now it is possible to write CForms wizards by writing javascript 
>>> FSMs in the form definition using widget states. Or if you prefer, 
>>> by using flowscript back-button magic, and automatic selection of 
>>> what is validated based on what widgets you use in your template.
>>
>
> Before I answer I'd like to point out that the bugzilla entry 
> illustrates two different things: flowscript "back-button magic" for 
> CForms and "validating what's in the template". Even if they in 
> combination IMO is a very promising candidate for having easy to wrte 
> multi page wizards in Cocon, they can be evaluated and used separatly.


Sure.

> The flowscript stuff can be used together with widget states and could 
> be put into the trunk quite soon. A better metod for communicating 
> between the form and the flow script form handling code is needed 
> first. And I would also prefer to discuss the code and idea a little 
> bit first as it is intricate stuff. I will hopefully find time to 
> write an RT about the details soon.
>
> The "validating what's in the template" is IMO promising stuff and is 
> part of the CForms refactoring vision, that I talk about all the time 
> ;) But it is not ready for prime time yet. It is on going work.
>
>> There's a problem by validating what's in the template, IMO: this 
>> means that if the template is wrong, i.e. it misses some important 
>> widget defined by the form, the form will be incorrectly considered 
>> valid.
>
>
> Sure, IMO, you should always do a complete validation of _all_ widgets 
> before binding your form model to business data. There is the same 
> problem with widget states, you can have faulty event logic so that 
> you happens to hide some subtree during all states in the filling in 
> of the multi form.


Sure, but forgetting a whole subform within the event handling is less 
likely to happen than forgetting a single widget in the template. 
Furthermore, we can automate the subform navigation and validation, not 
only using <fd:wizard-action> but also using a new <fd:wizard> container 
that would automatically iterate among its children (which are likely to 
be <fd:struct> themselves).

> So, partial validation is used after each sub form in a wizard to give 
> immediate feedback. Then complete validation is done before using the 
> data. This is IMO the only safe option.


Exactly. But with template-driven wizard, you don't know where to go 
back if validation fails, whereas with definition-driven wizard, we 
simply redisplay the first invalid subcontainer. Or will you keep the 
list of used widgets with each step to find where a widget was firstly used?

>> Also, this behaviour only validates terminal widgets and no container 
>> widgets, which may carry some additional semantic checks like row 
>> uniqueness in a repeater.
>
>
> I'm aware of that as you can see in the bugzilla comment, and have not 
> thought that much about of it yet. One possibillity could be to let 
> value change "bubble" and let the container validators trigger on 
> child events. Any other ideas? I have not used container validators 
> yet, so I don't know that much about the use cases.


The current behaviour is recursive depth-first validation, i.e. a 
container triggers its own validators if all of its children are valid. 
I'm not sure bubbling could do the trick, as validation is handled 
separately from value-changed events, and we have to know where to stop 
bubbling. Bubbling up to the Form is likely not to work, as validation 
will fail on required fields that weren't in the template.

>> So although reading only widgets present in the original template may 
>> make sense, using that same widget list for validation is wrong. 
>
>
> Wrong. based on missing parent validation, or are there further reasons?


Yes, missing parent validation, and also the difficulty to detect faulty 
wizard pages and going back to them.

>> And again, registering this list of used widgets will become useless 
>> once widgets don't reset their values if their corresponding 
>> parameter is not present. I'm just waiting for the release before 
>> adding this new feature.
>
>
> Wrong and useless, you are using strong words Sylvain ;)


Well, yes because I see too many potential problems with this approach 
compared to the apparent simplicity it brings!

> If we can find a good solution of the parent validation problem, it is 
> rather usefull as we only need to tell about what widgets that we want 
> to validate once, in the view. Furthermore, even if I have no 
> immediate need for that, Jonas has shown that it makes it safe to use 
> a form frame work without having a form model in between the view and 
> the "business data".


Uh, no form model and still safe? I missed that...

>> Furthermore, flowscript back-button magic implies that we can only 
>> navigate back to the previous screen, and not in an arbitrary screen 
>> in the sequence.
>
>
> I implemented it in that way because I didn't had any use cases for 
> something more complicated. But you can send a "go back" message 
> together with a web continuation id to the form handler, by using that 
> the form handler can first save the current form data and then jumping 
> to any previous continuation. I'll explain the details in the above 
> promised "back-button magic" RT.


Things I don't like in this back-button magic:
- not all forms are wizard, rather the contrary. So having the wizard 
engine plugged in deep in CForms doesn't seem good to mee.
- it's magic, meaning the fact that the user can go back is even not 
apparent in the flowscript.
- it is limited to CForms only, meaning if other pages are placed 
inbetween (regular pages, other form handling, etc), they cannot 
participate in the wizard navigation.

We had such a discussion one year ago and at that time I proposed a 
wizard API [1] that makes use of bookmarks and PageLocal (that did not 
existed at that time). Such a wizard API would make the fact that a 
wizard-style interaction is setup explicit in the flowscript, without 
requiring much more coding, especially if we integrate CForms in the 
wizard API (rather than putting wizards in CForms).

Example:

function myWizard() {

    var form = new Form("blah.xml");

    var wizard = new Wizard();
    // allow showForm() to handle wizard navigation
    form.setWizard(wizard);

    wizard.markStep("step1");
    form.showForm("foo1.html");

    wizard.markStep("step2");
    cocoon.sendPageAndWait("dialog.html", {wizard:wizard}");
    wizard.handleNavigation();

    wizard.markStep("step3");
    form.showForm("foo3.html");

    ... etc ...
}

The "markStep()" method is used to create a named continuation that can 
later be used to go back to any previous step in the navigation chain.

This approach allows to use wizard-style navigation with any kind of 
page, and not only forms. And if we want to go further, we could even 
make wizards a built-in feature of flowscript, i.e. add some methods to 
the "cocoon" object such as:
- cocoon.startWizard()
- cocoon.wizardStep(name)
- cocoon.finishWizard() // to invalidate all continuations in a wizard

The backwards navigation could then be handled automatically by the 
sendPageAndWait() method. Yes, that would be magic as you'll have 
nothing special to write, except "cocoon.startWizard()", which 
implictely says "let's start the magic, I know it will happen from now on".

That proposal may seem rather in opposition with the state-driven wizard 
sample I wrote, but I think not. Flowscript-level wizards are useful for 
complex interactions and navigation, whereas form-level wizards are 
useful to simply split a large form throughout several screens, when 
there is no need for navigation decision (i.e. the next screen doesn't 
depend on values in the current or previous screens). Think of it as a 
server-side handling of form tabs (see the form1 sample in CForms).

>>> But in the later case you miss the joy of writing all the javascript 
>>> event handling code ;)
>>
>>
>> Sure, but you still need a lot of <jx:if> in the template, wheareas 
>> activating/hiding groups means you just declare all groups 
>> (fd:struct) in the template and it adapts automatically.
>
>
> Either you decide what should be shown together in the view or in the 
> model. You get <jx:if> (or separate templates), in the first case and 
> fd:structs in the second. IMHO it is better to code view aspects, like 
> what should be shown in the same sub view, in the view than in the 
> model. It will be easier to reuse the model for several views, e.g. 
> specialist view (one screen), wizard view and pda wizard view, if you 
> don't put the view groupings in the model.


Mmmh... I agree and disagree at the same time :-)

The various widgets that will be presented in a multi-page navigation 
will be grouped by their relations, i.e. a page will show a consistent 
set of related data. And when displaying the same data in a single page, 
it's very likely that the same grouping will be used to lay out the 
page, using e.g. <fieldset> elements.

In that case, the difference between the multi-page and single-page 
templates will be that only one of these groups will be visible a one 
time in the multi-page template.

>> And while writing the sample, some new <fd:wizard-action> widgets 
>> with builtin event handling popped up in my head, just like we have 
>> today <fd:repeater-action> and <fd:row-action>. No more javascript 
>> event-handling, no <jx:if>.
>
>
> Seem like good ideas.
>
>> One last point also: being able to split a form across multiple page 
>> may allow for multi-channel forms, where the full form is shown on a 
>> regular browser, whereas it is split across several pages for PDAs or 
>> phones. That split can be decided by the view, choosing the 
>> appropriate template depending on the browser type, with no impact on 
>> the flowscript which will just have a single form.showForm().
>
>
> :) So we booth belive that multi chanel wizards mainly should affect 
> the view. But you want AFAIU to have event based flow control in the 
> model and I prefer to have flowscript based flow control.


The event-driven model allows to have the *exact same* flowscript 
whether the form is displayed in a single page or across multiple pages. 
This is important in a multi-channel application as, although the view 
will be different, the application logic should be the same whatever 
kind of browser the user has.

> We introduced flowscripts in Cocoon once because we thought that it 
> was a better way to control flow in e.g. wizards than using FSMs, were 
> we wrong?


Certainly not! But there may be a need for lower-level controllers, 
which in that case is implemented in a event-driven way by using 
continuations to handle those events.

> A problem with coding where we are in the wizard, booth as a widget 
> state and a flowscript state (i.e. where we are in the form handling 
> loop), is that previous continuations might get inconsistent. What 
> happens if the user happens to use the browser back button in a widget 
> state based wizard e.g.


Using a single continuation within the form.showForm loop (which would 
therefore no more be formally a loop) may be a way to handle this.

> Anyway, thanks for evaluating the proposal and comming with 
> constructive critic. I have some interesting new things to consider :)


Sure!

Sylvain

[1] http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106683720017320&w=2

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: CForms Wizards

Posted by Daniel Fagerstrom <da...@nada.kth.se>.
Sylvain Wallez wrote:
> Daniel Fagerstrom wrote:
<snip/>
>> Take a look at http://issues.apache.org/bugzilla/show_bug.cgi?id=32169 
>> where I have enhanced work of Jonas Ekstedt so that one can do the 
>> kind of things you asked for in the section about multi page forms in 
>> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106672364131946&w=2.
>>
>> So now it is possible to write CForms wizards by writing javascript 
>> FSMs in the form definition using widget states. Or if you prefer, by 
>> using flowscript back-button magic, and automatic selection of what is 
>> validated based on what widgets you use in your template.

Before I answer I'd like to point out that the bugzilla entry 
illustrates two different things: flowscript "back-button magic" for 
CForms and "validating what's in the template". Even if they in 
combination IMO is a very promising candidate for having easy to wrte 
multi page wizards in Cocon, they can be evaluated and used separatly.

The flowscript stuff can be used together with widget states and could 
be put into the trunk quite soon. A better metod for communicating 
between the form and the flow script form handling code is needed first. 
And I would also prefer to discuss the code and idea a little bit first 
as it is intricate stuff. I will hopefully find time to write an RT 
about the details soon.

The "validating what's in the template" is IMO promising stuff and is 
part of the CForms refactoring vision, that I talk about all the time ;) 
But it is not ready for prime time yet. It is on going work.

> There's a problem by validating what's in the template, IMO: this means 
> that if the template is wrong, i.e. it misses some important widget 
> defined by the form, the form will be incorrectly considered valid.

Sure, IMO, you should always do a complete validation of _all_ widgets 
before binding your form model to business data. There is the same 
problem with widget states, you can have faulty event logic so that you 
happens to hide some subtree during all states in the filling in of the 
multi form.

So, partial validation is used after each sub form in a wizard to give 
immediate feedback. Then complete validation is done before using the 
data. This is IMO the only safe option.

> Also, this behaviour only validates terminal widgets and no container 
> widgets, which may carry some additional semantic checks like row 
> uniqueness in a repeater.

I'm aware of that as you can see in the bugzilla comment, and have not 
thought that much about of it yet. One possibillity could be to let 
value change "bubble" and let the container validators trigger on child 
events. Any other ideas? I have not used container validators yet, so I 
don't know that much about the use cases.

> So although reading only widgets present in the original template may 
> make sense, using that same widget list for validation is wrong. 

Wrong. based on missing parent validation, or are there further reasons?

> And 
> again, registering this list of used widgets will become useless once 
> widgets don't reset their values if their corresponding parameter is not 
> present. I'm just waiting for the release before adding this new feature.

Wrong and useless, you are using strong words Sylvain ;)

If we can find a good solution of the parent validation problem, it is 
rather usefull as we only need to tell about what widgets that we want 
to validate once, in the view. Furthermore, even if I have no immediate 
need for that, Jonas has shown that it makes it safe to use a form frame 
work without having a form model in between the view and the "business 
data".

> Furthermore, flowscript back-button magic implies that we can only 
> navigate back to the previous screen, and not in an arbitrary screen in 
> the sequence.

I implemented it in that way because I didn't had any use cases for 
something more complicated. But you can send a "go back" message 
together with a web continuation id to the form handler, by using that 
the form handler can first save the current form data and then jumping 
to any previous continuation. I'll explain the details in the above 
promised "back-button magic" RT.

>> But in the later case you miss the joy of writing all the javascript 
>> event handling code ;)
> 
> Sure, but you still need a lot of <jx:if> in the template, wheareas 
> activating/hiding groups means you just declare all groups (fd:struct) 
> in the template and it adapts automatically.

Either you decide what should be shown together in the view or in the 
model. You get <jx:if> (or separate templates), in the first case and 
fd:structs in the second. IMHO it is better to code view aspects, like 
what should be shown in the same sub view, in the view than in the 
model. It will be easier to reuse the model for several views, e.g. 
specialist view (one screen), wizard view and pda wizard view, if you 
don't put the view groupings in the model.

> And while writing the sample, some new <fd:wizard-action> widgets with 
> builtin event handling popped up in my head, just like we have today 
> <fd:repeater-action> and <fd:row-action>. No more javascript 
> event-handling, no <jx:if>.

Seem like good ideas.

> One last point also: being able to split a form across multiple page may 
> allow for multi-channel forms, where the full form is shown on a regular 
> browser, whereas it is split across several pages for PDAs or phones. 
> That split can be decided by the view, choosing the appropriate template 
> depending on the browser type, with no impact on the flowscript which 
> will just have a single form.showForm().

:) So we booth belive that multi chanel wizards mainly should affect the 
view. But you want AFAIU to have event based flow control in the model 
and I prefer to have flowscript based flow control.

We introduced flowscripts in Cocoon once because we thought that it was 
a better way to control flow in e.g. wizards than using FSMs, were we wrong?

A problem with coding where we are in the wizard, booth as a widget 
state and a flowscript state (i.e. where we are in the form handling 
loop), is that previous continuations might get inconsistent. What 
happens if the user happens to use the browser back button in a widget 
state based wizard e.g.

                            ---o0o---

Anyway, thanks for evaluating the proposal and comming with constructive 
critic. I have some interesting new things to consider :)

/Daniel

Re: CForms Wizards

Posted by Sylvain Wallez <sy...@apache.org>.
Daniel Fagerstrom wrote:

> Reinhard Poetz wrote:
>
>>  --- Sylvain Wallez <sy...@apache.org> schrieb:
>>
>>> Reinhard Poetz wrote:
>>>
>>>> Sylvain Wallez wrote:
>>>>
>>>>> Sylvain Wallez wrote:
>>>>>
>>>>>> Sorry to rain on the party, but the new widget state stuff in 
>>>>>> CForms should make building multi-page forms a piece of cake.
>>>>>> Off writing an example....
>>>>>
>>>>>
>>>>> Done, I wrote my first wizard with CForms :-)
>>>>>
> <snip/>
>
>> Thanks for your remarks. If nobody beats my, I'll try
>> to implement the wizard example by following your
>> ideas next week.
>> -- 
>> Reinhard
>
>
> Take a look at http://issues.apache.org/bugzilla/show_bug.cgi?id=32169 
> where I have enhanced work of Jonas Ekstedt so that one can do the 
> kind of things you asked for in the section about multi page forms in 
> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106672364131946&w=2.
>
> So now it is possible to write CForms wizards by writing javascript 
> FSMs in the form definition using widget states. Or if you prefer, by 
> using flowscript back-button magic, and automatic selection of what is 
> validated based on what widgets you use in your template.


There's a problem by validating what's in the template, IMO: this means 
that if the template is wrong, i.e. it misses some important widget 
defined by the form, the form will be incorrectly considered valid. 
Also, this behaviour only validates terminal widgets and no container 
widgets, which may carry some additional semantic checks like row 
uniqueness in a repeater.

So although reading only widgets present in the original template may 
make sense, using that same widget list for validation is wrong. And 
again, registering this list of used widgets will become useless once 
widgets don't reset their values if their corresponding parameter is not 
present. I'm just waiting for the release before adding this new feature.

Furthermore, flowscript back-button magic implies that we can only 
navigate back to the previous screen, and not in an arbitrary screen in 
the sequence.

> But in the later case you miss the joy of writing all the javascript 
> event handling code ;)


Sure, but you still need a lot of <jx:if> in the template, wheareas 
activating/hiding groups means you just declare all groups (fd:struct) 
in the template and it adapts automatically.

And while writing the sample, some new <fd:wizard-action> widgets with 
builtin event handling popped up in my head, just like we have today 
<fd:repeater-action> and <fd:row-action>. No more javascript 
event-handling, no <jx:if>.

One last point also: being able to split a form across multiple page may 
allow for multi-channel forms, where the full form is shown on a regular 
browser, whereas it is split across several pages for PDAs or phones. 
That split can be decided by the view, choosing the appropriate template 
depending on the browser type, with no impact on the flowscript which 
will just have a single form.showForm().

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: CForms Wizards

Posted by Daniel Fagerstrom <da...@nada.kth.se>.
Reinhard Poetz wrote:
>  --- Sylvain Wallez <sy...@apache.org> schrieb: 
>>Reinhard Poetz wrote:
>>>Sylvain Wallez wrote:
>>>>Sylvain Wallez wrote:
>>>>>Sorry to rain on the party, but the new widget
>>>>>state stuff in CForms 
>>>>>should make building multi-page forms a piece of
>>>>>cake.
>>>>>Off writing an example....
>>>>
>>>>Done, I wrote my first wizard with CForms :-)
>>>>
<snip/>
> Thanks for your remarks. If nobody beats my, I'll try
> to implement the wizard example by following your
> ideas next week.
> --
> Reinhard

Take a look at http://issues.apache.org/bugzilla/show_bug.cgi?id=32169 
where I have enhanced work of Jonas Ekstedt so that one can do the kind 
of things you asked for in the section about multi page forms in 
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=106672364131946&w=2.

So now it is possible to write CForms wizards by writing javascript FSMs 
in the form definition using widget states. Or if you prefer, by using 
flowscript back-button magic, and automatic selection of what is 
validated based on what widgets you use in your template. But in the 
later case you miss the joy of writing all the javascript event handling 
code ;)

/Daniel

Re: CForms Wizards

Posted by Reinhard Poetz <re...@yahoo.de>.
 --- Sylvain Wallez <sy...@apache.org> schrieb: 
> Reinhard Poetz wrote:
> 
> > Sylvain Wallez wrote:
> >
> >> Sylvain Wallez wrote:
> >>
> >>> Sorry to rain on the party, but the new widget
> state stuff in CForms 
> >>> should make building multi-page forms a piece of
> cake.
> >>>
> >>> Off writing an example....
> >>
> >>
> >> Done, I wrote my first wizard with CForms :-)
> >>
> >> Please update branch 2.1.x and point your browser
> to 
> >>
>
http://localhost:8888/forms-samples/do-multipage.flow
> >>
> >> Enjoy!
> >
> >
> > Great, thanks for the example! One question: IIUC
> the wizard is driven 
> > by the widget states and the event handling
> mechanism.
> 
> 
> Yes: the various "pages" are widget groups
> (fd:struct) whose state is 
> set either to active or invisible depending on the
> displayed page. The 
> initial state, in the form definition, is to have
> only page1 being 
> active, others being invisible. Navigation is
> managed by fd:action that 
> change the page state. "next" validates the current
> page whereas "prev" 
> doesn't. On the last page, a fd:submit goes back to
> flowscript if 
> validation is successful.
> 
> > This may solve many use cases but would it be
> possible to control 
> > which part of the form is shown by the controller
> (flowscript) which 
> > would bring some more flexibility (mix in
> non-forms pages, jump to 
> > different sub-pages)?
> 
> 
> That is possible if you use fd:submit instead of
> fd:action when control 
> has to come back to flowscript. Since only the
> active widgets are 
> validated, the submit will be sucessful if the
> widgets in the current 
> page are valid, not taking other pages into account.
> It's then the 
> flowscript's responsibility to display the
> appropriate page when calling 
> again form.showForm().
> 
> > [some pseudocode ...]
> > var myFlow() {
> >   var form = new Form("myForm");
> >   form.load(myBean);
> >   form.showSubForm("myPipeline", "../page1");
> >   cocoon.sendPageAndWait("showAnotherPage");
> >   form.showSubForm("myPipeline", "../page");
> >   form.save(myBean);
> > }
> 
> 
> The "showSubForm" above would simply set all pages
> to invisible state 
> except the one defined by the second parameter
> (which should be "pageX" 
> rather than "../pageX").
> 
> > And while writing this, another question came up:
> What's the best way 
> > to deal with validation errors? example: On page 2
> the users enters 
> > something that wouldn't let page 1 validate any
> more. Can we handle this?
> 
> 
> Validation of the last page could revalidate
> previous pages in order, 
> and switch back to the first one that doesn't
> validate successfully.
> 
> That could be something like:
> 
> function validateWizard() {
>   currentPage.setState(WidgetState.INVISIBLE); //
> another one may be 
> chosen below
>   for (page in pageList) {
>     page.setState(WidgetState.ACTIVE);
>     if (page.validate()) {
>       page.setState(WidgetState.INVISIBLE);
>     } else {
>       return false; // validation failed
>     }
>   }
> }
> 
> 
> Setting the page state to active before calling
> validate() is important 
> as non-active widgets are not validated. That isn't
> a problem here since 
> we must redisplay a page that doesn't validate, but
> I'm thinking of 
> adding a Widget.validate(boolean force) method, that
> would, when "force" 
> is true, validate widgets whatever their state.

Thanks for your remarks. If nobody beats my, I'll try
to implement the wizard example by following your
ideas next week.

--
Reinhard


	

	
		
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 100MB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de

Re: CForms Wizards

Posted by Sylvain Wallez <sy...@apache.org>.
Reinhard Poetz wrote:

> Sylvain Wallez wrote:
>
>> Sylvain Wallez wrote:
>>
>>> Sorry to rain on the party, but the new widget state stuff in CForms 
>>> should make building multi-page forms a piece of cake.
>>>
>>> Off writing an example....
>>
>>
>> Done, I wrote my first wizard with CForms :-)
>>
>> Please update branch 2.1.x and point your browser to 
>> http://localhost:8888/forms-samples/do-multipage.flow
>>
>> Enjoy!
>
>
> Great, thanks for the example! One question: IIUC the wizard is driven 
> by the widget states and the event handling mechanism.


Yes: the various "pages" are widget groups (fd:struct) whose state is 
set either to active or invisible depending on the displayed page. The 
initial state, in the form definition, is to have only page1 being 
active, others being invisible. Navigation is managed by fd:action that 
change the page state. "next" validates the current page whereas "prev" 
doesn't. On the last page, a fd:submit goes back to flowscript if 
validation is successful.

> This may solve many use cases but would it be possible to control 
> which part of the form is shown by the controller (flowscript) which 
> would bring some more flexibility (mix in non-forms pages, jump to 
> different sub-pages)?


That is possible if you use fd:submit instead of fd:action when control 
has to come back to flowscript. Since only the active widgets are 
validated, the submit will be sucessful if the widgets in the current 
page are valid, not taking other pages into account. It's then the 
flowscript's responsibility to display the appropriate page when calling 
again form.showForm().

> [some pseudocode ...]
> var myFlow() {
>   var form = new Form("myForm");
>   form.load(myBean);
>   form.showSubForm("myPipeline", "../page1");
>   cocoon.sendPageAndWait("showAnotherPage");
>   form.showSubForm("myPipeline", "../page");
>   form.save(myBean);
> }


The "showSubForm" above would simply set all pages to invisible state 
except the one defined by the second parameter (which should be "pageX" 
rather than "../pageX").

> And while writing this, another question came up: What's the best way 
> to deal with validation errors? example: On page 2 the users enters 
> something that wouldn't let page 1 validate any more. Can we handle this?


Validation of the last page could revalidate previous pages in order, 
and switch back to the first one that doesn't validate successfully.

That could be something like:

function validateWizard() {
  currentPage.setState(WidgetState.INVISIBLE); // another one may be 
chosen below
  for (page in pageList) {
    page.setState(WidgetState.ACTIVE);
    if (page.validate()) {
      page.setState(WidgetState.INVISIBLE);
    } else {
      return false; // validation failed
    }
  }
}


Setting the page state to active before calling validate() is important 
as non-active widgets are not validated. That isn't a problem here since 
we must redisplay a page that doesn't validate, but I'm thinking of 
adding a Widget.validate(boolean force) method, that would, when "force" 
is true, validate widgets whatever their state.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }