You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Sylvain Wallez <sy...@anyware-tech.com> on 2003/09/18 23:47:04 UTC

Event handling in Woody

Hi all,

A short post to say that I've been working intensively on event handling 
on Woody since yesterday. I'm nearly finished with it, and obtained 
something powerful-yet-simple, that allows to define event handlers on 
actions (ActionEvent) and fields (ValueChangeEvent). The goal is also to 
allow event listeners to be written both in Java (classic-style) and in 
JavaScript (flowscript-style).

This morning, I was reading an article about JavaServerFaces (never did 
look at it before), digged a bit, and discovered that what I was doing 
was very close to JSF event handling, and grabbed some interesting 
points. Digged further, and found the lifecycle thing very interesting, 
and once again close to the way Woody handles form processing. Parts of 
the JSF are not so bad and can be a good inspiration source ;-)

Once this infrastructure is in place, I plan to write specialized 
repeater-actions that automatically handle add/delete row in repeaters.

More soon...

Sylvain

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



Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Bruno Dumon wrote:

>On Fri, 2003-09-26 at 10:59, Sylvain Wallez wrote:
>  
>
>>TO ALL:
>>I invite you to look at the "Various", "Flowscript" and "Car selector" Woody samples in the latest CVS. These demonstrate the styling and event-handling features I added to Woody, and I'd be interested in having feedback on this.
>>    
>>
>
>No time to look in detail at it right now, but I noticed a little problem with the car selector: if I select a make, type and model, and then change the make again, it gives an exception.
>

Doh ! I forgot to cvs add a new source file (EmptySelectionList). Should 
be ok now !

><snip/>
>  
>
>>An noticeble thing, though : calling Field.getValue() _validates_ the field's value, meaning that even if the whole form should not be validated, local validation messages can appear, related to the event handlers that have been triggered. This gives some useful feedback to the user when an intra-form action cannot be performed because the fields used by this action are invalid.
>>    
>>
>
>Hmmm, wouldn't it then be better to add an isValid() method to the Widget interface? I think it's best if getValue() simply returns the value, and doesn't cause any magic side-effects. Also, previously getValue() returned the value of the widget even if it wasn't valid, and the conversion from string to object was done in the readFromRequest() method.
>

I wanted getValue() to return something only if the value is fully 
valid, and not only syntactically correct. Otherwise an application may 
break simply because the value is out of range if it forgets to check 
isValid(). This behaviour protects the application.

But I was also thinking about adding a getEnteredValue() which would 
return the String value read on the request, even if not valid. This 
would allow to get the raw value in the cases where it's needed.

What do you think ?

Sylvain

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



Re: Event handling in Woody

Posted by Bruno Dumon <br...@outerthought.org>.
On Fri, 2003-09-26 at 10:59, Sylvain Wallez wrote:
> TO ALL:
> I invite you to look at the "Various", "Flowscript" and "Car selector" 
> Woody samples in the latest CVS. These demonstrate the styling and 
> event-handling features I added to Woody, and I'd be interested in 
> having feedback on this.

No time to look in detail at it right now, but I noticed a little
problem with the car selector: if I select a make, type and model, and
then change the make again, it gives an exception.

<snip/>
> An noticeble thing, though : calling Field.getValue() _validates_ the 
> field's value, meaning that even if the whole form should not be 
> validated, local validation messages can appear, related to the event 
> handlers that have been triggered. This gives some useful feedback to 
> the user when an intra-form action cannot be performed because the 
> fields used by this action are invalid.

Hmmm, wouldn't it then be better to add an isValid() method to the
Widget interface? I think it's best if getValue() simply returns the
value, and doesn't cause any magic side-effects. Also, previously
getValue() returned the value of the widget even if it wasn't valid, and
the conversion from string to object was done in the readFromRequest()
method.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: Event handling in Woody

Posted by Andreas Hochsteger <e9...@student.tuwien.ac.at>.

Sylvain Wallez wrote:
> Andreas Hochsteger wrote:
> 
>> Sylvain Wallez wrote:
> 
> 
> <snip/>
> 
>>> Now handlers involving widgets only (and not app-data) may be sent to 
>>> the client, but this would require to reconsitute an equivalent of 
>>> the form model on the client. Not easy, but I'm not a client-side JS 
>>> expert... Want to give it a try ?
>>
>>
>>
>> I'm not either ... :-(
>>
>> One more question comes to my mind:
>> How hard would it be to support XUL applications with Woody?
> 
> 
> 
> Look at woody-field-styling.xsl and woody-page-styling.xsl and write 
> their XUL version ! Want to give it a try, this time ? ;-)

Perhaps ;-)

> Sylvain
> 

Andreas


Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Andreas Hochsteger wrote:

> Sylvain Wallez wrote:

<snip/>

>> Now handlers involving widgets only (and not app-data) may be sent to 
>> the client, but this would require to reconsitute an equivalent of 
>> the form model on the client. Not easy, but I'm not a client-side JS 
>> expert... Want to give it a try ?
>
>
> I'm not either ... :-(
>
> One more question comes to my mind:
> How hard would it be to support XUL applications with Woody?


Look at woody-field-styling.xsl and woody-page-styling.xsl and write 
their XUL version ! Want to give it a try, this time ? ;-)

Sylvain

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



Re: Event handling in Woody

Posted by Andreas Hochsteger <e9...@student.tuwien.ac.at>.
Sylvain Wallez wrote:

> Andreas Hochsteger wrote:
> 
>> Hi Sylvain!
>>
>> Sylvain Wallez wrote:
>>
>>> <snip/>
>>>
>>> I solved points 3&4 as follows :
>>> - <wd:action> are considered as "intra-form" actions : they never 
>>> validate and always redisplay the form
>>> - <wd:submit> (new widget that extends action) are considered as 
>>> "form-exit" actions. They have an additional "validate" attribute 
>>> that define if form validation should occur (true by default). For 
>>> example, this allows a "cancel" button to be written as <wd:submit 
>>> id="cancel" validate="false"/>
>>
>>
>>
>> Would it be possible (perhaps in the future) to handle those 
>> intra-form actions completely on the client (eg. via JavaScript)?
>> Imagine using some DHTML to add or delete rows...
>>
>> Not that I'd need it right now, but I'm just curious, if you thought 
>> about something like that.
> 
> 
> 
> Yes, I thought about that, and I even wrote some add/remove stuff for 
> XMLForm before switching to Woody. But this can be very tricky to do as 
> it highly depends on how the form widgets map to HTML code.
 >
> And since this mapping is defined by the form template, you can't rely 
> on the fact that a repeater is laid out in a particular way. This could 
> be done, however, if the layout of a repeater was templated using a new 
> instance-only widget like the wi:group defined in "woody-page-styling.xsl".
> 
> Now the repeaters are only a small part of event-handling, as actions 
> can be used to do many other things such as getting the (parsed and 
> validated) value of other fields, accessing application data, etc. This 
> server-side event handling allow to simply define complex form 
> interactions at the cost of a roundtrip to the server. I'm currenlty 
> investingating in moving form styling on XSL-enabled clients (Mozilla 
> and IE6) which would speed up this rountripping.
> 
> Now handlers involving widgets only (and not app-data) may be sent to 
> the client, but this would require to reconsitute an equivalent of the 
> form model on the client. Not easy, but I'm not a client-side JS 
> expert... Want to give it a try ?

I'm not either ... :-(

One more question comes to my mind:
How hard would it be to support XUL applications with Woody?

> Sylvain
> 

Andreas



Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Andreas Hochsteger wrote:

> Hi Sylvain!
>
> Sylvain Wallez wrote:
>
>> <snip/>
>>
>> I solved points 3&4 as follows :
>> - <wd:action> are considered as "intra-form" actions : they never 
>> validate and always redisplay the form
>> - <wd:submit> (new widget that extends action) are considered as 
>> "form-exit" actions. They have an additional "validate" attribute 
>> that define if form validation should occur (true by default). For 
>> example, this allows a "cancel" button to be written as <wd:submit 
>> id="cancel" validate="false"/>
>
>
> Would it be possible (perhaps in the future) to handle those 
> intra-form actions completely on the client (eg. via JavaScript)?
> Imagine using some DHTML to add or delete rows...
>
> Not that I'd need it right now, but I'm just curious, if you thought 
> about something like that.


Yes, I thought about that, and I even wrote some add/remove stuff for 
XMLForm before switching to Woody. But this can be very tricky to do as 
it highly depends on how the form widgets map to HTML code.

And since this mapping is defined by the form template, you can't rely 
on the fact that a repeater is laid out in a particular way. This could 
be done, however, if the layout of a repeater was templated using a new 
instance-only widget like the wi:group defined in "woody-page-styling.xsl".

Now the repeaters are only a small part of event-handling, as actions 
can be used to do many other things such as getting the (parsed and 
validated) value of other fields, accessing application data, etc. This 
server-side event handling allow to simply define complex form 
interactions at the cost of a roundtrip to the server. I'm currenlty 
investingating in moving form styling on XSL-enabled clients (Mozilla 
and IE6) which would speed up this rountripping.

Now handlers involving widgets only (and not app-data) may be sent to 
the client, but this would require to reconsitute an equivalent of the 
form model on the client. Not easy, but I'm not a client-side JS 
expert... Want to give it a try ?

Sylvain

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



Re: Event handling in Woody

Posted by Andreas Hochsteger <e9...@student.tuwien.ac.at>.
Hi Sylvain!

Sylvain Wallez wrote:

> <snip/>
> 
> I solved points 3&4 as follows :
> - <wd:action> are considered as "intra-form" actions : they never 
> validate and always redisplay the form
> - <wd:submit> (new widget that extends action) are considered as 
> "form-exit" actions. They have an additional "validate" attribute that 
> define if form validation should occur (true by default). For example, 
> this allows a "cancel" button to be written as <wd:submit id="cancel" 
> validate="false"/>

Would it be possible (perhaps in the future) to handle those intra-form 
actions completely on the client (eg. via JavaScript)?
Imagine using some DHTML to add or delete rows...

Not that I'd need it right now, but I'm just curious, if you thought 
about something like that.

Bye,

	Andreas



Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
TO ALL:
I invite you to look at the "Various", "Flowscript" and "Car selector" 
Woody samples in the latest CVS. These demonstrate the styling and 
event-handling features I added to Woody, and I'd be interested in 
having feedback on this.


Marc Portier wrote:

> [on communicating from event handlers to controller]
>
>>>> Yep. But using hidden widgets for this doesn't seem the right 
>>>> solution for me. I thought of adding get/setAttribute on Widget (or 
>>>> only on Form?), but did not found a real need for it now. Maybe 
>>>> it's needed after all...
>>>>
>>>
>>> yes there is: as I explained there is obvious need for
>>> 1/ event listeners that only are responsible for dynamic effects on 
>>> the 'view' (which can be handled by this)
>>> 2/ but in the general case there is obviously also need for 
>>> event-listeners that hook up into the 'controller'
>>>
>>> for the latter I find get/setAttribute only marginally better then 
>>> hidden widgets: both add a loose contract where a strong one is 
>>> possible, thus removing guidance from compile time check and 
>>> introducing possible errors... 
>>
>>
>> Mmmh... hidden widgets may actually be better in that case since they 
>> are typed, and can be checked at runtime since they have to be 
>> declared in the form definition.
>>
>> What I don't like much, however, is that we introduce app-related 
>> things in the form definition. Or perhaps we should define a new 
>> <app-data> widget that is never sent to the client nor read from the 
>> request ?
>
>
> We discussed some get/setAppContext() on the form before IIRC
> (when considering business related validation)
>
> We somewhat agreed already then that it could be usefull, but I'm 
> still not totally assured that it is really needed, nor if the form is 
> the best place to put it.
>
> In any case looking at your description of app-data:
> - never sent to the client
> - nor read from the request
>
> we should ask ourself 'what has it to do with the form?'
> feels like dragging in concerns, no?
>
> problem: event-handler needs to talk to controller!
> observation: they both know the form
> hack: lets abuse the form as the messenger?
>
> I know above statement is putting it stronger then how I really 
> perceive it, but I really want us to take a deep breath and think some 
> more before just following the path of least resistance? 


Well, we can consider, as you say above, that the form is the 
articulation point between the user and the application. With this 
definition in mind, having elements in the form only related to this 
communication makes sense.

And this somewhat already is the case with the <aggregate-field> widget 
that holds data only of interest to the application. And will be also 
the case with the event-dispatchers we talked about. So I finally have 
no problems with having a non-visual <app-data> widget.

> <snip/>
>
>
> [on the event-dispatchers for everything]
>
>> Event-dispatcher may prove useful when there's a need to link the 
>> use-case controller to the widget tree, but I don't think everything 
>> should go through these dispatchers. In most cases, event handling 
>> will not require this relation to the controller and having to define 
>> a dispatcher for every widgets wanting to handle events will quickly 
>> become overly verbose.
>
>
> I see your point. I guess I've been exposed to too much Java and XML:
> verbosity becomes a second nature ;-) 


In that case, it's not only about verbosity, but about complexity caused 
by too much hyperlinking !

>> So I think we need both. And as I alreday mentioned, we can consider 
>> sending events to an event-dispatcher as a special case of event 
>> listener.
>
>
> yes, that is the main point to hold on to!
> I'll try to look to your additions asap so I can give the dispatchers 
> a go as well 


Cool.

> [other thoughts introduced...]
>
>> Some more thoughs that came to me :
>> 1 - what about a <on-load> event handler that would be called once 
>> the widget tree is first set up ?
>
>
> hm, for additional arbitrary setup that is totally form related and 
> which you don't want to copy accross the different controllers that 
> use the form (and would know themselves about the event anyway)
>
> just out of interest: this means you would need to do things that 
> currently can't be expressed in the woody-definition form? any 
> examples in your mind already? 


Nope. No real useful example. And even less considering that 
"on-value-changed" is triggered also in the form loading phase.

>> 2 - I'd like to add a "disabled" property to <action> widgets. 
>> Depending on what happens on the form, we may want to allow or not 
>> certain actions.
>
>
> yep 


Ok. I'll add it.

>> 3 - I'd like to find an easy way to indicate if an <action> should 
>> terminate the form or if it's a intra-form action (such as add-row on 
>> a repeater) which leads to redisplay the form.
>
>
> again this sounds (to me) like events that should go out to the 
> controller that created the form which seems best entitled to close it 
> down too.
> in this case however the idea of some form related state 
> 'displayOn/Off' being set makes more sense (then setAppData())
>
>> 4 - similarily, I'd like to have a way to indicate if an <action> 
>> should try to validate the values. For example a "cancel" button will 
>> terminate the form without trying to validate it.
>

<snip/>

I solved points 3&4 as follows :
- <wd:action> are considered as "intra-form" actions : they never 
validate and always redisplay the form
- <wd:submit> (new widget that extends action) are considered as 
"form-exit" actions. They have an additional "validate" attribute that 
define if form validation should occur (true by default). For example, 
this allows a "cancel" button to be written as <wd:submit id="cancel" 
validate="false"/>

An noticeble thing, though : calling Field.getValue() _validates_ the 
field's value, meaning that even if the whole form should not be 
validated, local validation messages can appear, related to the event 
handlers that have been triggered. This gives some useful feedback to 
the user when an intra-form action cannot be performed because the 
fields used by this action are invalid.

Sylvain

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



Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Marc Portier wrote:

> Sylvain,
>
> sorry for this late entry (quite off line this week)...
> hoping the long wait didn't stop your thought train
> (also haven't got time to check commit-mails so I don't really know 
> how far you are already with this)


I just commited the whole thing a few minutes ago ;-)

Going to bed now, I'll read your remarks tomorrow.

Cheers,
Sylvain

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



Re: Event handling in Woody

Posted by Marc Portier <mp...@outerthought.org>.
Sylvain,

sorry for this late entry (quite off line this week)...
hoping the long wait didn't stop your thought train
(also haven't got time to check commit-mails so I don't really know how 
far you are already with this)


Sylvain Wallez wrote:
> Marc Portier wrote:
> 
>> Sylvain Wallez wrote:


[on communicating from event handlers to controller]

>>> Yep. But using hidden widgets for this doesn't seem the right 
>>> solution for me. I thought of adding get/setAttribute on Widget (or 
>>> only on Form?), but did not found a real need for it now. Maybe it's 
>>> needed after all...
>>>
>>
>> yes there is: as I explained there is obvious need for
>> 1/ event listeners that only are responsible for dynamic effects on 
>> the 'view' (which can be handled by this)
>> 2/ but in the general case there is obviously also need for 
>> event-listeners that hook up into the 'controller'
>>
>> for the latter I find get/setAttribute only marginally better then 
>> hidden widgets: both add a loose contract where a strong one is 
>> possible, thus removing guidance from compile time check and 
>> introducing possible errors... 
> 
> 
> 
> Mmmh... hidden widgets may actually be better in that case since they 
> are typed, and can be checked at runtime since they have to be declared 
> in the form definition.
> 
> What I don't like much, however, is that we introduce app-related things 
> in the form definition. Or perhaps we should define a new <app-data> 
> widget that is never sent to the client nor read from the request ?
> 

We discussed some get/setAppContext() on the form before IIRC
(when considering business related validation)

We somewhat agreed already then that it could be usefull, but I'm still 
not totally assured that it is really needed, nor if the form is the 
best place to put it.

In any case looking at your description of app-data:
- never sent to the client
- nor read from the request

we should ask ourself 'what has it to do with the form?'
feels like dragging in concerns, no?

problem: event-handler needs to talk to controller!
observation: they both know the form
hack: lets abuse the form as the messenger?

I know above statement is putting it stronger then how I really perceive 
it, but I really want us to take a deep breath and think some more 
before just following the path of least resistance?


<snip/>


[on the event-dispatchers for everything]

> Event-dispatcher may prove useful when there's a need to link the 
> use-case controller to the widget tree, but I don't think everything 
> should go through these dispatchers. In most cases, event handling will 
> not require this relation to the controller and having to define a 
> dispatcher for every widgets wanting to handle events will quickly 
> become overly verbose.
> 

I see your point. I guess I've been exposed to too much Java and XML:
verbosity becomes a second nature ;-)

> So I think we need both. And as I alreday mentioned, we can consider 
> sending events to an event-dispatcher as a special case of event listener.
> 

yes, that is the main point to hold on to!
I'll try to look to your additions asap so I can give the dispatchers a 
go as well


<big_snip>
Thx for removing my doubths on the changes for the repeater, although I 
will not have time until after the GT
</big_snip>


[other thoughts introduced...]

> Some more thoughs that came to me :
> 1 - what about a <on-load> event handler that would be called once the 
> widget tree is first set up ?
> 

hm, for additional arbitrary setup that is totally form related
and which you don't want to copy accross the different controllers
that use the form (and would know themselves about the event anyway)

just out of interest: this means you would need to do things that 
currently can't be expressed in the woody-definition form? any examples 
in your mind already?


> 2 - I'd like to add a "disabled" property to <action> widgets. Depending 
> on what happens on the form, we may want to allow or not certain actions.
> 

yep

> 3 - I'd like to find an easy way to indicate if an <action> should 
> terminate the form or if it's a intra-form action (such as add-row on a 
> repeater) which leads to redisplay the form.
> 

again this sounds (to me) like events that should go out to the 
controller that created the form which seems best entitled to close it 
down too.

in this case however the idea of some form related state 'displayOn/Off' 
being set makes more sense (then setAppData())

> 4 - similarily, I'd like to have a way to indicate if an <action> should 
> try to validate the values. For example a "cancel" button will terminate 
> the form without trying to validate it.
> 

again, maybe just an eventhandler that can set a state-flag 
'validationOn/Off' on the form?

> For points 3 & 4, two solutions come to my mind :
> - add 2 new attributes on <action> : validate="true|false" and 
> end-form="true|false". Of course if validate="true", the form is 
> redisplayed if validation fails even if end-form="true".

yes, quite a useful shorthand to the above event-handler that is setting 
form-state idea... (but essentially the same, no?)

> - distinguish <action> and <submit> : an <action> would not terminate 
> the form while a <submit> would. Both would have a "validate" attribute, 
> but its default value would be "false" for <action> and "true" for 
> <submit>.
> 
> What do you think ?
> 

all makes sense IMHO.

-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org




Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Marc Portier wrote:

> Sylvain Wallez wrote:


>> I understand your point and went through it also. But remember an 
>
>
> wow! a historic event (I made myself clear at first attempt)


And without a body-language video attachment ;-)

>> important point : repeaters dynamically create widgets, meaning you 
>> can't attach an event listener directly on the widget contained in a 
>> repeater, otherwise similar widgets in different rows will not have 
>> the same behaviour.
>>
>> Now a WidgetEvent contains the source widget along with the 
>> FormContext that was used when it was generated. And I also added a 
>> FormContext.getForm() to access the root of the widget tree.
>>
>
> sounds good, it's pretty much what I understood/expected
>
>>> so it could change state-information in the model (userData area or 
>>> hidden widgets) and as such it becomes available to the 
>>> use-case-controller since it has a point to the form and can expect it. 
>>
>>
>>
>>
>> Yep. But using hidden widgets for this doesn't seem the right 
>> solution for me. I thought of adding get/setAttribute on Widget (or 
>> only on Form?), but did not found a real need for it now. Maybe it's 
>> needed after all...
>>
>
> yes there is: as I explained there is obvious need for
> 1/ event listeners that only are responsible for dynamic effects on 
> the 'view' (which can be handled by this)
> 2/ but in the general case there is obviously also need for 
> event-listeners that hook up into the 'controller'
>
> for the latter I find get/setAttribute only marginally better then 
> hidden widgets: both add a loose contract where a strong one is 
> possible, thus removing guidance from compile time check and 
> introducing possible errors... 


Mmmh... hidden widgets may actually be better in that case since they 
are typed, and can be checked at runtime since they have to be declared 
in the form definition.

What I don't like much, however, is that we introduce app-related things 
in the form definition. Or perhaps we should define a new <app-data> 
widget that is never sent to the client nor read from the request ?

<snip/>

> well what I thought I read was: you seemed to 'queue' up events in a 
> channel to be sent out only later
>
> but this clarification makes me see you send them back over the 
> originating widget, which would probably not be neccessary if we use 
> the event-dispatchers which are defined on the form level any way, no?
>
> then form processing would allow all widgets to post their events in 
> their assigned queue where they are hold untill processing is 
> completed and thus only sent out at a moment where all widgets were in 
> a new state (which is mucho important, didn't realize until you 
> mentioned it, nice one to catch!) 


Event-dispatcher may prove useful when there's a need to link the 
use-case controller to the widget tree, but I don't think everything 
should go through these dispatchers. In most cases, event handling will 
not require this relation to the controller and having to define a 
dispatcher for every widgets wanting to handle events will quickly 
become overly verbose.

So I think we need both. And as I alreday mentioned, we can consider 
sending events to an event-dispatcher as a special case of event listener.

>> Not exactly : events are registered on the FormContext and 
>> broadcasted back to their originating widget once the current 
>> processing phase is finished. As we speak, I'm listing these phases 
>> and found the following :
>> - load (binding)
>> - readFromRequest (may be this should be merged with load in a "get 
>> value" phase ?)
>> - validate,
>> - save (binding)
>
>
> ah, you mean each of these processing-phases could possibly result in 
> events been thrown, so not only the readFromRequest? 


Yes. For example, we can imagine that a (yet-undefined) 
ValidationChangedEvent on a purchase order ID field can lead to change 
the contents of the repeater containing the items of the purchase order. 
The ValueChangedEvent won't be enough in that case since we must not 
only ensure that the ID is correct, but also that it actually exists in 
the purchase-order database.

JSF seems to resend all events at every phase (unless I missed 
something). I don't know if this is good, as it may be difficult for an 
EventHandler to know if it already has handled a given event.

<snip/>

>>>> I'm thinking of adding a new "submit-on-change" attribute on 
>>>> <wi:styling>, but I'm wondering if this belongs to the view or to 
>>>> the form definition. Seems better on the view.
>>>
>>>
>>> yep, that's what Bruno did, if you like, I can check how he did it.
>>
>>
>> onchange="getForm(this).submit()" ? Maybe with an additional hidden 
>> field indicating that it's not a "normal" submit ?
>
>
> yep, and AFAIR the hidden field was just the action-widget itself! 


I came to something a bit different : the hidden field contains the ID 
of the widget that triggered the submission if it's not a "normal" 
submit form element (like <input type="submit">). This allows to easily 
determine server-side where the submit originates from.

Anyway, I'd be interested in knowing Bruno's approach.

<snip/>

>>> what I meant is that the control itself would be remembering what 
>>> happened to the rows in between two calls to some method that sets a 
>>> 'resetRowModificationInfo()' which would then be called to set some 
>>> revision-point between which the control would be remembering some 
>>> metadata on each of the rows.
>>>
>>> of course this borrows from the current way binding is used: once at 
>>> the start (load) and once at the end (save) of the use case.
>>
>>
>> Can't this directly be implemented in the repeater itself ? The 
>> repeater tracks row modifications, and the binding is responsible to 
>> call resetRowModificationInfo(), recordRowModifications(true) and 
>> getRowModificationInfo()
>
>
> yep, that is what I was thinking and then the getRowModificationInfo() 
> could provide for a interateNewRows() iterateDeletedRows() 
> iterateStillExistingRows() to make it ever more easy ;-) 


No problem : once we say that a repeater can record modifications, we 
can define the API necessary to easily use this information.

>>> looking at how this often maps to talking to a (persistency) backend 
>>> system I'm not really tempted into changing this usage pattern for now
>>>
>>> of course if we agree that stacking up these changes are not part of 
>>> the  concern of the widget itseld, then we will need a listener of 
>>
>
> I agree that making it a concern of the repeater-widget itself just 
> makes things a lot easier
>
> However I'm still somewhat doubthing if we should.
> question: Is 'we like it for the binding' enough of a justification to 
> add this concern to the repeater-widget ?
>
> (of course: if it is useful to the binding it will also be useful to 
> people that don't use the binding but are handling the changes 
> programatically, right?)
>
> also adding the recordRowModificationInfo(true) helps me see we could 
> just do it: it indicates that it really is an exteral concern we can 
> add dynamically (I like) 


Mmmh... not sure I understood all the details here. Do you mean that 
repeater recording could simply be a particular implementation of an 
RepeaterEventListener ? Yes. This would separate the recording concern 
from the widget itself.

This RecordingListener could even be created by the repeater binding itself.

<snip/>

>>> sorry here, I started mixing use-case controller (i.e flow-script or 
>>> apple) and the eventListener... as shown above they often go hand in 
>>> hand: some eventListeners only affect the view itself, but some of 
>>> them really have to callback into the state of the use-case.
>>
>>
>> Ah, ok, I understand. Then either the event-dispatcher stuff or 
>> adding attributes to widgets may be the solution.
>
>
> yes, but we prefer... ;-) 

... <wd:app-data> widgets for typing and runtime checks ? No problem !

Some more thoughs that came to me :
1 - what about a <on-load> event handler that would be called once the 
widget tree is first set up ?

2 - I'd like to add a "disabled" property to <action> widgets. Depending 
on what happens on the form, we may want to allow or not certain actions.

3 - I'd like to find an easy way to indicate if an <action> should 
terminate the form or if it's a intra-form action (such as add-row on a 
repeater) which leads to redisplay the form.

4 - similarily, I'd like to have a way to indicate if an <action> should 
try to validate the values. For example a "cancel" button will terminate 
the form without trying to validate it.

For points 3 & 4, two solutions come to my mind :
- add 2 new attributes on <action> : validate="true|false" and 
end-form="true|false". Of course if validate="true", the form is 
redisplayed if validation fails even if end-form="true".
- distinguish <action> and <submit> : an <action> would not terminate 
the form while a <submit> would. Both would have a "validate" attribute, 
but its default value would be "false" for <action> and "true" for <submit>.

What do you think ?

Sylvain

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



Re: Event handling in Woody

Posted by Marc Portier <mp...@outerthought.org>.

Sylvain Wallez wrote:

> Marc Portier wrote:
> 
>> Sylvain Wallez wrote:
> 
> 
> <snip/>
> 
>> hm, this makes these listeners totally stateless, no?
>> what I mean:
>> - probably woody is going to instantiate them with a Class.forname() 
>> and newInstance() sequence, correct?
>> - as such they have no initial state other then some defaults 
>> (no-argument-constructor)
>> - consequence: they don't have pointers into our use-case controllers 
>> (be it flowscript or apples) like is the case with swing and the usage 
>> of anonymous inner classes.  Point being: it is going to be hard to 
>> callback into your business logic with these events, no?
>>
>> as a way out I see the following approaches:
>> 1/ keep like above:
>> so the eventListener doesn't have direct access to the use-case 
>> controller, but at least it has access to the Woody Form model, right? 
> 
> 
> 
> I understand your point and went through it also. But remember an 

wow! a historic event (I made myself clear at first attempt)

> important point : repeaters dynamically create widgets, meaning you 
> can't attach an event listener directly on the widget contained in a 
> repeater, otherwise similar widgets in different rows will not have the 
> same behaviour.
> 
> Now a WidgetEvent contains the source widget along with the FormContext 
> that was used when it was generated. And I also added a 
> FormContext.getForm() to access the root of the widget tree.
> 

sounds good, it's pretty much what I understood/expected

>> so it could change state-information in the model (userData area or 
>> hidden widgets) and as such it becomes available to the 
>> use-case-controller since it has a point to the form and can expect it. 
> 
> 
> 
> Yep. But using hidden widgets for this doesn't seem the right solution 
> for me. I thought of adding get/setAttribute on Widget (or only on 
> Form?), but did not found a real need for it now. Maybe it's needed 
> after all...
> 

yes there is: as I explained there is obvious need for
1/ event listeners that only are responsible for dynamic effects on the 
'view' (which can be handled by this)
2/ but in the general case there is obviously also need for 
event-listeners that hook up into the 'controller'

for the latter I find get/setAttribute only marginally better then 
hidden widgets: both add a loose contract where a strong one is 
possible, thus removing guidance from compile time check and introducing 
possible errors...


>> What I dislike about this is that the active-event-trigger becomes a 
>> passive data element waiting to be read.
>>
>> 2/ have the form-model declare named event-dispatchers
>> which behave like a sort of event-queue-channels
>>
>> <wd:event-dispatcher type="value-changed" name="foo_changed" />
>>
>> <wd:field id="foo">
>>  ...
>>  <wd:on-change>
>>    <wd:java event-dispatcher="foo_changed"/>
>>
>> and add methods on the form model so the use case controller can 
>> register it's own instances to receive events from these named 
>> event-queue-channels:
>>
>> form.registerValueChangedListener(
>>           "foo_changed",
>>            new ValueChangedListener(){
>>
>>                public void valueChanged(ValueChangedEvent evt){
>>                    Widget source = evt.getSource();
>>                    Object newValue = evt.getNewValue();
>>                    ...
>>                    EnclosingClass.this.whatEverStateVariable = ...;
>>                }
>>         });
>>
>>
>> we avoid the 'dynamic widget instance' problem you mentioned above
>> and we can easily have eventListeners that can callback into our use 
>> case controllers... 
> 
> 
> 
> I see your point. This IMO fits into the current architecture as it can 
> simply be a new "DispatcherEventListener" implementation. Isn't this 
> also somewhat similar to the "broadcasters" in XUL ?

sorry don't know XUL, but I do feal you understood what I meant

> 
>> obviously from my text I like 2/ the most, since it could also be 
>> incrementally added to your current stuff? 
> 
> 
> 
> Yep.
> 
>> what do you think? 
> 
> Sounds good !
> 
>>>    <wd:javascript>
>>>       var list = this.parent.getWidget("thelist");
>>>       list.selectionList = 
>>> Packages.com.my.App.getSelectionForTheList(this.value);
>>>    </wd:javascript>
>>>  </wd:on-change>
>>> </wd:field>
>>>
>>> Similarily, there's an <on-activate> on <action> widgets.
>>
>>
>>
>> would probably have chosen on-valueChange and on-action, but that's a 
>> matter of taste probably
>>
>>> I reused the JSF patterns for event handling : events are buffered 
>>> until the current processing phase is finished and fired afterwards, 
>>> to ensure the widget tree is in a consistent state.
>>
>>
>>
>> sounds like you already have something like event-dispatchers in place? 
> 

well what I thought I read was: you seemed to 'queue' up events in a 
channel to be sent out only later

but this clarification makes me see you send them back over the 
originating widget, which would probably not be neccessary if we use the 
event-dispatchers which are defined on the form level any way, no?

then form processing would allow all widgets to post their events in 
their assigned queue where they are hold untill processing is completed 
and thus only sent out at a moment where all widgets were in a new state 
(which is mucho important, didn't realize until you mentioned it, nice 
one to catch!)

> 
> Not exactly : events are registered on the FormContext and broadcasted 
> back to their originating widget once the current processing phase is 
> finished. As we speak, I'm listing these phases and found the following :
> - load (binding)
> - readFromRequest (may be this should be merged with load in a "get 
> value" phase ?)
> - validate,
> - save (binding)
> 

ah, you mean each of these processing-phases could possibly result in 
events been thrown, so not only the readFromRequest?

yep, makes sense!

>>> I still have to define also the ability for the form to be submitted 
>>> when a widget's value changes. Considering the car selector example, 
>>> this would allow to refresh the model list as soon as the maker is 
>>> changed withouth having to push the "select maker" button.
>>
>>
>>
>> you mean having a client-side javascript thingy to do a submit-on-change? 
> 
> 
> 
> Yep.
> 
>> I saw Bruno tinkering on something like this, IIRC it was triggering 
>> an action (since we didn't have value-changed events)
>>
>> only downside of it is that you have to add a no-value option to the 
>> list which is selected by default in order to trigger the change:
>>
>> the list then shows the text (select one from the list) otherwise you 
>> can't trigger the generation of the select-maker if e.g. the option 
>> you want to make is the default selected one :-) 
> 
> 
> 
> We must assume that the form is in a consistent state when sent to the 
> browser. I mean in the above example, the model-list should have been 
> updated before the form is sent. This can be achieved automagically with 
> the "on-change" (or "on-value-change") being triggered during the "get 
> value" phase (binding or reading from the request).
> 

yesyesyes... following the thought-train, right on!

>>> I'm thinking of adding a new "submit-on-change" attribute on 
>>> <wi:styling>, but I'm wondering if this belongs to the view or to the 
>>> form definition. Seems better on the view.
>>
>>
>>
>> yep, that's what Bruno did, if you like, I can check how he did it.
> 
> 
> 
> onchange="getForm(this).submit()" ? Maybe with an additional hidden 
> field indicating that it's not a "normal" submit ?
> 

yep, and AFAIR the hidden field was just the action-widget itself!

>>>> also this links back to another wild idea I'm having
>>>> I'm still not quite satisfied with the way the repeater-binding (the 
>>>> not simple one) needs to operate for detecting 
>>>> new/deleted/syill-existing rows in the repeater...
>>>>
>>>> So I hope the way you handle valuechanged can give some inspiration 
>>>> on how to mark the changed state of repeater rows? 
>>>
>>>
>>>
>>> Aha ! I was also thinking of an event-driven binding, but kept this 
>>> wild idea for now : the binding would register itself on the repeater 
>>> and "collect" modifications.
>>
>>
>>
>> yep, it is different to what I was thinking but it might serve as an 
>> alternative.
>>
>> what I meant is that the control itself would be remembering what 
>> happened to the rows in between two calls to some method that sets a 
>> 'resetRowModificationInfo()' which would then be called to set some 
>> revision-point between which the control would be remembering some 
>> metadata on each of the rows.
>>
>> of course this borrows from the current way binding is used: once at 
>> the start (load) and once at the end (save) of the use case.
> 
> 
> 
> Can't this directly be implemented in the repeater itself ? The repeater 
> tracks row modifications, and the binding is responsible to call 
> resetRowModificationInfo(), recordRowModifications(true) and 
> getRowModificationInfo()
> 

yep, that is what I was thinking
and then the getRowModificationInfo() could provide for a 
interateNewRows() iterateDeletedRows() iterateStillExistingRows() to 
make it ever more easy ;-)

>> looking at how this often maps to talking to a (persistency) backend 
>> system I'm not really tempted into changing this usage pattern for now
>>
>> of course if we agree that stacking up these changes are not part of 
>> the  concern of the widget itseld, then we will need a listener of 

I agree that making it a concern of the repeater-widget itself just 
makes things a lot easier

However I'm still somewhat doubthing if we should.
question: Is 'we like it for the binding' enough of a justification to 
add this concern to the repeater-widget ?

(of course: if it is useful to the binding it will also be useful to 
people that don't use the binding but are handling the changes 
programatically, right?)

also adding the recordRowModificationInfo(true) helps me see we could 
just do it: it indicates that it really is an exteral concern we can add 
dynamically (I like)

>> some kind to do it for us... still have to think about how the Binding 
>> could then get a hold of those results.
>>
>>>> BTW: I assume that the ValueChangedEvent is holding both the old and 
>>>> new value? 
>>>
>>>
>>>
>>> Of course !
>>
>>
>>
>> yep, but what I really meant is that I was assuming that the widget 
>> was remembering both old and new states (which I realize now it is 
>> probably not) 
> 
> 
> 
> Ah, you mean the widget itself ? No : the old value is lost. But is it 
> really useful to keep the old value if the ValueChangedEvent has it ?
> 

Nope.

I have to admit I was trying to find in your current work some 
argumentation for adding my repeater-concern expained above...

you know this kind of reasoning:
<< If we add 'oldValue' to fields just for the events, it would somewhat 
justify my lingering addition to the repeaters??? >>

I reallize the reasoning is a false one to make (but so human ;-))

In every case talking about it resulted in a finer way to solve things...

>>>>> allow event listeners to be written both in Java (classic-style) 
>>>>> and in JavaScript (flowscript-style).
>>>>
>>>>
>>>>
>>>> Makes sense.
>>>>
>>>> I guess reusing the awt eventhandling interfaces is out of the 
>>>> question? 
>>>
>>>
>>>
>>> Using AWTEvent doesn't really makes sense, but the new FormEvent 
>>> class extends java.util.EventObject, and the listeners extend 
>>> java.util.EventListener. However, I used the convenient 
>>> AWTEventMulticaster as the base class for a FormEventMulticaster.
>>>
>>>> Not that I would consider it as a breaking design point to start 
>>>> using it, but yesterday someone showed me usage of jbeaver (see at 
>>>> http://www.ratundtat.com/index01.htm?menue=40, it's not oss but it 
>>>> didn't look entirely impossible to create something similar.) and I 
>>>> couldn't help dreaming about a common GUI description language that 
>>>> could result into both Swing and Woody based apps...
>>>
>>>
>>>
>>> And SWT... Some of my current wild thoughts is to use Woody and 
>>> flowscript to build Eclipse plugins. Imagine every component coming 
>>> with its own Woody form and associated flowscript and binding : 
>>> building a Cocoon IDE for Eclipse can become quite easy.
>>
>>
>>
>> yep, but what I meant was this: in order to be able to swap from the 
>> one to the other it would be really nice to also be able to re-use the 
>> use-case controllers and their accompanying eventListeners...
>>
>> of course if we go for this event-dispatcher idea that would still 
>> hold, no? 
> 
> 
> 
> Further thinking needed on this : I'm concentrating on the "normal" use 
> of forms for now to avoid energy dispersion ;-)
> 

no pro, I have no direct need for this (nor much spare time ATM)
and this is just more stuff we can dig up during the hackathon ;-)

main idea was however: (in wild mode)
supposing we have something that can generate a 'woody form' represented 
in a set of swing or swt widgets in an standalone app (which was the 
topic here) and assuming we go for the event-dispatchers

then the same use case controller could simply use the same 
form.registerValueChangedListener(dispatcherName, myWoodyListener); in 
the swt/swing context, it would just be the internal machinery that maps 
low level awt events to the correct dispatcher (thus the dispatch idea 
allows hiding the specifics of either web-requests or awt events, thus 
enabling reuse of more code...)

>>>> From that angle: being able to share your event-controllers might 
>>>> make sense (although wrapping them inside specific listener 
>>>> interfaces should not be that hard) 
>>>
>>>
>>>
>>> Sorry, don't understand: what are "event-controllers" ?
>>
>>
>>
>> sorry here, I started mixing use-case controller (i.e flow-script or 
>> apple) and the eventListener... as shown above they often go hand in 
>> hand:
>>
>> some eventListeners only affect the view itself, but some of them 
>> really have to callback into the state of the use-case.
> 
> 
> 
> Ah, ok, I understand. Then either the event-dispatcher stuff or adding 
> attributes to widgets may be the solution.
> 

yes, but we prefer... ;-)

regards,
-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Marc Portier wrote:

> Sylvain Wallez wrote:

<snip/>

> hm, this makes these listeners totally stateless, no?
> what I mean:
> - probably woody is going to instantiate them with a Class.forname() 
> and newInstance() sequence, correct?
> - as such they have no initial state other then some defaults 
> (no-argument-constructor)
> - consequence: they don't have pointers into our use-case controllers 
> (be it flowscript or apples) like is the case with swing and the usage 
> of anonymous inner classes.  Point being: it is going to be hard to 
> callback into your business logic with these events, no?
>
> as a way out I see the following approaches:
> 1/ keep like above:
> so the eventListener doesn't have direct access to the use-case 
> controller, but at least it has access to the Woody Form model, right? 


I understand your point and went through it also. But remember an 
important point : repeaters dynamically create widgets, meaning you 
can't attach an event listener directly on the widget contained in a 
repeater, otherwise similar widgets in different rows will not have the 
same behaviour.

Now a WidgetEvent contains the source widget along with the FormContext 
that was used when it was generated. And I also added a 
FormContext.getForm() to access the root of the widget tree.

> so it could change state-information in the model (userData area or 
> hidden widgets) and as such it becomes available to the 
> use-case-controller since it has a point to the form and can expect it. 


Yep. But using hidden widgets for this doesn't seem the right solution 
for me. I thought of adding get/setAttribute on Widget (or only on 
Form?), but did not found a real need for it now. Maybe it's needed 
after all...

> What I dislike about this is that the active-event-trigger becomes a 
> passive data element waiting to be read.
>
> 2/ have the form-model declare named event-dispatchers
> which behave like a sort of event-queue-channels
>
> <wd:event-dispatcher type="value-changed" name="foo_changed" />
>
> <wd:field id="foo">
>  ...
>  <wd:on-change>
>    <wd:java event-dispatcher="foo_changed"/>
>
> and add methods on the form model so the use case controller can 
> register it's own instances to receive events from these named 
> event-queue-channels:
>
> form.registerValueChangedListener(
>           "foo_changed",
>            new ValueChangedListener(){
>
>                public void valueChanged(ValueChangedEvent evt){
>                    Widget source = evt.getSource();
>                    Object newValue = evt.getNewValue();
>                    ...
>                    EnclosingClass.this.whatEverStateVariable = ...;
>                }
>         });
>
>
> we avoid the 'dynamic widget instance' problem you mentioned above
> and we can easily have eventListeners that can callback into our use 
> case controllers... 


I see your point. This IMO fits into the current architecture as it can 
simply be a new "DispatcherEventListener" implementation. Isn't this 
also somewhat similar to the "broadcasters" in XUL ?

> obviously from my text I like 2/ the most, since it could also be 
> incrementally added to your current stuff? 


Yep.

> what do you think? 


Sounds good !

>>    <wd:javascript>
>>       var list = this.parent.getWidget("thelist");
>>       list.selectionList = 
>> Packages.com.my.App.getSelectionForTheList(this.value);
>>    </wd:javascript>
>>  </wd:on-change>
>> </wd:field>
>>
>> Similarily, there's an <on-activate> on <action> widgets.
>
>
> would probably have chosen on-valueChange and on-action, but that's a 
> matter of taste probably
>
>> I reused the JSF patterns for event handling : events are buffered 
>> until the current processing phase is finished and fired afterwards, 
>> to ensure the widget tree is in a consistent state.
>
>
> sounds like you already have something like event-dispatchers in place? 


Not exactly : events are registered on the FormContext and broadcasted 
back to their originating widget once the current processing phase is 
finished. As we speak, I'm listing these phases and found the following :
- load (binding)
- readFromRequest (may be this should be merged with load in a "get 
value" phase ?)
- validate,
- save (binding)

>> I still have to define also the ability for the form to be submitted 
>> when a widget's value changes. Considering the car selector example, 
>> this would allow to refresh the model list as soon as the maker is 
>> changed withouth having to push the "select maker" button.
>
>
> you mean having a client-side javascript thingy to do a submit-on-change? 


Yep.

> I saw Bruno tinkering on something like this, IIRC it was triggering 
> an action (since we didn't have value-changed events)
>
> only downside of it is that you have to add a no-value option to the 
> list which is selected by default in order to trigger the change:
>
> the list then shows the text (select one from the list) otherwise you 
> can't trigger the generation of the select-maker if e.g. the option 
> you want to make is the default selected one :-) 


We must assume that the form is in a consistent state when sent to the 
browser. I mean in the above example, the model-list should have been 
updated before the form is sent. This can be achieved automagically with 
the "on-change" (or "on-value-change") being triggered during the "get 
value" phase (binding or reading from the request).

>> I'm thinking of adding a new "submit-on-change" attribute on 
>> <wi:styling>, but I'm wondering if this belongs to the view or to the 
>> form definition. Seems better on the view.
>
>
> yep, that's what Bruno did, if you like, I can check how he did it.


onchange="getForm(this).submit()" ? Maybe with an additional hidden 
field indicating that it's not a "normal" submit ?

>>> also this links back to another wild idea I'm having
>>> I'm still not quite satisfied with the way the repeater-binding (the 
>>> not simple one) needs to operate for detecting 
>>> new/deleted/syill-existing rows in the repeater...
>>>
>>> So I hope the way you handle valuechanged can give some inspiration 
>>> on how to mark the changed state of repeater rows? 
>>
>>
>> Aha ! I was also thinking of an event-driven binding, but kept this 
>> wild idea for now : the binding would register itself on the repeater 
>> and "collect" modifications.
>
>
> yep, it is different to what I was thinking but it might serve as an 
> alternative.
>
> what I meant is that the control itself would be remembering what 
> happened to the rows in between two calls to some method that sets a 
> 'resetRowModificationInfo()' which would then be called to set some 
> revision-point between which the control would be remembering some 
> metadata on each of the rows.
>
> of course this borrows from the current way binding is used: once at 
> the start (load) and once at the end (save) of the use case.


Can't this directly be implemented in the repeater itself ? The repeater 
tracks row modifications, and the binding is responsible to call 
resetRowModificationInfo(), recordRowModifications(true) and 
getRowModificationInfo()

> looking at how this often maps to talking to a (persistency) backend 
> system I'm not really tempted into changing this usage pattern for now
>
> of course if we agree that stacking up these changes are not part of 
> the  concern of the widget itseld, then we will need a listener of 
> some kind to do it for us... still have to think about how the Binding 
> could then get a hold of those results.
>
>>> BTW: I assume that the ValueChangedEvent is holding both the old and 
>>> new value? 
>>
>>
>> Of course !
>
>
> yep, but what I really meant is that I was assuming that the widget 
> was remembering both old and new states (which I realize now it is 
> probably not) 


Ah, you mean the widget itself ? No : the old value is lost. But is it 
really useful to keep the old value if the ValueChangedEvent has it ?

>>>> allow event listeners to be written both in Java (classic-style) 
>>>> and in JavaScript (flowscript-style).
>>>
>>>
>>> Makes sense.
>>>
>>> I guess reusing the awt eventhandling interfaces is out of the 
>>> question? 
>>
>>
>> Using AWTEvent doesn't really makes sense, but the new FormEvent 
>> class extends java.util.EventObject, and the listeners extend 
>> java.util.EventListener. However, I used the convenient 
>> AWTEventMulticaster as the base class for a FormEventMulticaster.
>>
>>> Not that I would consider it as a breaking design point to start 
>>> using it, but yesterday someone showed me usage of jbeaver (see at 
>>> http://www.ratundtat.com/index01.htm?menue=40, it's not oss but it 
>>> didn't look entirely impossible to create something similar.) and I 
>>> couldn't help dreaming about a common GUI description language that 
>>> could result into both Swing and Woody based apps...
>>
>>
>> And SWT... Some of my current wild thoughts is to use Woody and 
>> flowscript to build Eclipse plugins. Imagine every component coming 
>> with its own Woody form and associated flowscript and binding : 
>> building a Cocoon IDE for Eclipse can become quite easy.
>
>
> yep, but what I meant was this: in order to be able to swap from the 
> one to the other it would be really nice to also be able to re-use the 
> use-case controllers and their accompanying eventListeners...
>
> of course if we go for this event-dispatcher idea that would still 
> hold, no? 


Further thinking needed on this : I'm concentrating on the "normal" use 
of forms for now to avoid energy dispersion ;-)

>>> From that angle: being able to share your event-controllers might 
>>> make sense (although wrapping them inside specific listener 
>>> interfaces should not be that hard) 
>>
>>
>> Sorry, don't understand: what are "event-controllers" ?
>
>
> sorry here, I started mixing use-case controller (i.e flow-script or 
> apple) and the eventListener... as shown above they often go hand in 
> hand:
>
> some eventListeners only affect the view itself, but some of them 
> really have to callback into the state of the use-case.


Ah, ok, I understand. Then either the event-dispatcher stuff or adding 
attributes to widgets may be the solution.

Sylvain

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



Re: Event handling in Woody

Posted by Marc Portier <mp...@outerthought.org>.

Sylvain Wallez wrote:

> Marc Portier wrote:
> 

<snip />

> 
> Well, if you fail to explain to yourself, I understand why we sometimes 
> don't understand your posts ;-D
> 

doh!
care to explain this joke to us?
;-)


but I have to admit I mostly need other people around to develop own 
ideas, makes me a perfect guy for OSS in fact: the ideas are never 
really only *my* ideas, so I 'm very rarely struggling with 
idea-ownership, rather the contrary: struggling with idea-lonelyness ;-)


>> care to textualize some preview on what goes about before we see the 
>> code? 
> 
> Yep. Here it is.
> 
> At first, I wanted to add event listeners to widgets (i.e. the 
> _instances_), but that did not work, primarily because a repeater 
> dynamically creates widget instances and secondly because it requires 
> listeners to be painfully defined programmatically each time a form is 
> instanciated (in an action or flowscript).
> 
> So event listeners are defined in the form definition. I currently have 
> defined a ValueChangedEvent for data-aware widgets (field, booleanfield, 
> aggregatefield) and ActionEvent for actions. We also need a RepeaterEvent.
> 
> Two implementations of EventListenerBuilder exist : one that creates a 
> Java class (classical EventListener) and one that wraps a JavaScript 
> snippet. Just as in DHTML, that snippet has some predefined variable : 
> this (the widget) and event. If called within a flowscript, it also has 
> access to the precious "cocoon" object. I still have to see how to 
> create a "cocoon" object if used out of the flowscript context.
> 
> The definition therefore looks like this :
> <wd:field id="foo">
>  ...
>  <wd:on-change>
>    <wd:java class="com.my.Listener"/>

hm, this makes these listeners totally stateless, no?
what I mean:
- probably woody is going to instantiate them with a Class.forname() and 
newInstance() sequence, correct?
- as such they have no initial state other then some defaults 
(no-argument-constructor)
- consequence: they don't have pointers into our use-case controllers 
(be it flowscript or apples) like is the case with swing and the usage 
of anonymous inner classes.  Point being: it is going to be hard to 
callback into your business logic with these events, no?

as a way out I see the following approaches:
1/ keep like above:
so the eventListener doesn't have direct access to the use-case 
controller, but at least it has access to the Woody Form model, right?

so it could change state-information in the model (userData area or 
hidden widgets) and as such it becomes available to the 
use-case-controller since it has a point to the form and can expect it.

What I dislike about this is that the active-event-trigger becomes a 
passive data element waiting to be read.


2/ have the form-model declare named event-dispatchers
which behave like a sort of event-queue-channels

<wd:event-dispatcher type="value-changed" name="foo_changed" />

<wd:field id="foo">
  ...
  <wd:on-change>
    <wd:java event-dispatcher="foo_changed"/>

and add methods on the form model so the use case controller can 
register it's own instances to receive events from these named 
event-queue-channels:

form.registerValueChangedListener(
           "foo_changed",
            new ValueChangedListener(){

                public void valueChanged(ValueChangedEvent evt){
                    Widget source = evt.getSource();
                    Object newValue = evt.getNewValue();
                    ...
                    EnclosingClass.this.whatEverStateVariable = ...;
                }
         });


we avoid the 'dynamic widget instance' problem you mentioned above
and we can easily have eventListeners that can callback into our use 
case controllers...


obviously from my text I like 2/ the most, since it could also be 
incrementally added to your current stuff?

what do you think?

>    <wd:javascript>
>       var list = this.parent.getWidget("thelist");
>       list.selectionList = 
> Packages.com.my.App.getSelectionForTheList(this.value);
>    </wd:javascript>
>  </wd:on-change>
> </wd:field>
> 
> Similarily, there's an <on-activate> on <action> widgets.
> 

would probably have chosen on-valueChange and on-action, but that's a 
matter of taste probably

> I reused the JSF patterns for event handling : events are buffered until 
> the current processing phase is finished and fired afterwards, to ensure 
> the widget tree is in a consistent state.
> 

sounds like you already have something like event-dispatchers in place?

> I still have to define also the ability for the form to be submitted 
> when a widget's value changes. Considering the car selector example, 
> this would allow to refresh the model list as soon as the maker is 
> changed withouth having to push the "select maker" button.
> 

you mean having a client-side javascript thingy to do a submit-on-change?

I saw Bruno tinkering on something like this, IIRC it was triggering an 
action (since we didn't have value-changed events)

only downside of it is that you have to add a no-value option to the 
list which is selected by default in order to trigger the change:

the list then shows the text (select one from the list) otherwise you 
can't trigger the generation of the select-maker if e.g. the option you 
want to make is the default selected one :-)

> I'm thinking of adding a new "submit-on-change" attribute on 
> <wi:styling>, but I'm wondering if this belongs to the view or to the 
> form definition. Seems better on the view.

yep, that's what Bruno did, if you like, I can check how he did it.

> 
>> also this links back to another wild idea I'm having
>> I'm still not quite satisfied with the way the repeater-binding (the 
>> not simple one) needs to operate for detecting 
>> new/deleted/syill-existing rows in the repeater...
>>
>> So I hope the way you handle valuechanged can give some inspiration on 
>> how to mark the changed state of repeater rows? 
> 
> 
> 
> Aha ! I was also thinking of an event-driven binding, but kept this wild 
> idea for now : the binding would register itself on the repeater and 
> "collect" modifications.
> 

yep, it is different to what I was thinking but it might serve as an 
alternative.

what I meant is that the control itself would be remembering what 
happened to the rows in between two calls to some method that sets a 
'resetRowModificationInfo()' which would then be called to set some 
revision-point between which the control would be remembering some 
metadata on each of the rows.

of course this borrows from the current way binding is used: once at the 
start (load) and once at the end (save) of the use case.

looking at how this often maps to talking to a (persistency) backend 
system I'm not really tempted into changing this usage pattern for now

of course if we agree that stacking up these changes are not part of the 
  concern of the widget itseld, then we will need a listener of some 
kind to do it for us... still have to think about how the Binding could 
then get a hold of those results.


>> BTW: I assume that the ValueChangedEvent is holding both the old and 
>> new value? 
> 
> Of course !
> 

yep, but what I really meant is that I was assuming that the widget was 
remembering both old and new states (which I realize now it is probably not)

>>> allow event listeners to be written both in Java (classic-style) and 
>>> in JavaScript (flowscript-style).
>>
>>
>>
>> Makes sense.
>>
>> I guess reusing the awt eventhandling interfaces is out of the question? 
> 
> 
> 
> Using AWTEvent doesn't really makes sense, but the new FormEvent class 
> extends java.util.EventObject, and the listeners extend 
> java.util.EventListener. However, I used the convenient 
> AWTEventMulticaster as the base class for a FormEventMulticaster.
> 
>> Not that I would consider it as a breaking design point to start using 
>> it, but yesterday someone showed me usage of jbeaver (see at 
>> http://www.ratundtat.com/index01.htm?menue=40, it's not oss but it 
>> didn't look entirely impossible to create something similar.) and I 
>> couldn't help dreaming about a common GUI description language that 
>> could result into both Swing and Woody based apps...
> 
> 
> 
> And SWT... Some of my current wild thoughts is to use Woody and 
> flowscript to build Eclipse plugins. Imagine every component coming with 
> its own Woody form and associated flowscript and binding : building a 
> Cocoon IDE for Eclipse can become quite easy.
> 

yep, but what I meant was this: in order to be able to swap from the one 
to the other it would be really nice to also be able to re-use the 
use-case controllers and their accompanying eventListeners...

of course if we go for this event-dispatcher idea that would still hold, no?

>> From that angle: being able to share your event-controllers might make 
>> sense (although wrapping them inside specific listener interfaces 
>> should not be that hard) 
> 
> Sorry, don't understand: what are "event-controllers" ?
> 

sorry here, I started mixing use-case controller (i.e flow-script or 
apple) and the eventListener... as shown above they often go hand in hand:

some eventListeners only affect the view itself, but some of them really 
have to callback into the state of the use-case.

<snip />


-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


just come and see these bodies talk (was Re: Event handling in Woody)

Posted by Marc Portier <mp...@outerthought.org>.

Steven Noels wrote:

> Sylvain Wallez wrote:
> 
>> Marc Portier wrote:
 >>
>>> in fact I thought about this from the start, but failed to explain to 
>>> myself how it should look like (I also kept on mixing it up with 
>>> client-side javascript) 
> 
>> Well, if you fail to explain to yourself, I understand why we 
>> sometimes don't understand your posts ;-D
> 
> A ROFL from the peanut gallery. :-D
> 

c'mmon guys, I was silent on this topic, no?
I really wait to bug you all until I _can_ at least explain it to myself :-)

as for:

> In the office, there's of course the benefit of a whiteboard and all 
> visual clues of body language - maybe Marc should augment his posts with 
> a video taping of himself. ;-)

Well, I guess you'll have to see the great shape of this body (in a real 
good looking cocoon-t-shirt!) to really dig its language ;-)


Hm, at second thought: better find your own reason to come over to:
http://wiki.cocoondev.org/Wiki.jsp?page=GT2003Hackathon - 
http://www.orixo.com/events/gt2003/

;-)

-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


Re: Event handling in Woody

Posted by Steven Noels <st...@outerthought.org>.
Sylvain Wallez wrote:

> Marc Portier wrote:

>> in fact I thought about this from the start, but failed to explain to 
>> myself how it should look like (I also kept on mixing it up with 
>> client-side javascript) 

> Well, if you fail to explain to yourself, I understand why we sometimes 
> don't understand your posts ;-D

A ROFL from the peanut gallery. :-D

In the office, there's of course the benefit of a whiteboard and all 
visual clues of body language - maybe Marc should augment his posts with 
a video taping of himself. ;-)

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought - Open Source Java & XML            An Orixo Member
Read my weblog at            http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org                stevenn at apache.org


Re: Event handling in Woody

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Marc Portier wrote:

>
>
> Sylvain Wallez wrote:
>
>> Hi all,
>>
>> A short post to say that I've been working intensively on event 
>> handling on Woody since yesterday. I'm nearly finished with it, and 
>> obtained something powerful-yet-simple, that allows to define event 
>> handlers on actions (ActionEvent) and fields (ValueChangeEvent). The 
>> goal is also to 
>
>
> yoohoo!, looking forward.
> in fact I thought about this from the start, but failed to explain to 
> myself how it should look like (I also kept on mixing it up with 
> client-side javascript) 


Well, if you fail to explain to yourself, I understand why we sometimes 
don't understand your posts ;-D

> care to textualize some preview on what goes about before we see the 
> code? 


Yep. Here it is.

At first, I wanted to add event listeners to widgets (i.e. the 
_instances_), but that did not work, primarily because a repeater 
dynamically creates widget instances and secondly because it requires 
listeners to be painfully defined programmatically each time a form is 
instanciated (in an action or flowscript).

So event listeners are defined in the form definition. I currently have 
defined a ValueChangedEvent for data-aware widgets (field, booleanfield, 
aggregatefield) and ActionEvent for actions. We also need a RepeaterEvent.

Two implementations of EventListenerBuilder exist : one that creates a 
Java class (classical EventListener) and one that wraps a JavaScript 
snippet. Just as in DHTML, that snippet has some predefined variable : 
this (the widget) and event. If called within a flowscript, it also has 
access to the precious "cocoon" object. I still have to see how to 
create a "cocoon" object if used out of the flowscript context.

The definition therefore looks like this :
<wd:field id="foo">
  ...
  <wd:on-change>
    <wd:java class="com.my.Listener"/>
    <wd:javascript>
       var list = this.parent.getWidget("thelist");
       list.selectionList = 
Packages.com.my.App.getSelectionForTheList(this.value);
    </wd:javascript>
  </wd:on-change>
</wd:field>

Similarily, there's an <on-activate> on <action> widgets.

I reused the JSF patterns for event handling : events are buffered until 
the current processing phase is finished and fired afterwards, to ensure 
the widget tree is in a consistent state.

I still have to define also the ability for the form to be submitted 
when a widget's value changes. Considering the car selector example, 
this would allow to refresh the model list as soon as the maker is 
changed withouth having to push the "select maker" button.

I'm thinking of adding a new "submit-on-change" attribute on 
<wi:styling>, but I'm wondering if this belongs to the view or to the 
form definition. Seems better on the view.

> also this links back to another wild idea I'm having
> I'm still not quite satisfied with the way the repeater-binding (the 
> not simple one) needs to operate for detecting 
> new/deleted/syill-existing rows in the repeater...
>
> So I hope the way you handle valuechanged can give some inspiration on 
> how to mark the changed state of repeater rows? 


Aha ! I was also thinking of an event-driven binding, but kept this wild 
idea for now : the binding would register itself on the repeater and 
"collect" modifications.

> BTW: I assume that the ValueChangedEvent is holding both the old and 
> new value? 


Of course !

>> allow event listeners to be written both in Java (classic-style) and 
>> in JavaScript (flowscript-style).
>
>
> Makes sense.
>
> I guess reusing the awt eventhandling interfaces is out of the question? 


Using AWTEvent doesn't really makes sense, but the new FormEvent class 
extends java.util.EventObject, and the listeners extend 
java.util.EventListener. However, I used the convenient 
AWTEventMulticaster as the base class for a FormEventMulticaster.

> Not that I would consider it as a breaking design point to start using 
> it, but yesterday someone showed me usage of jbeaver (see at 
> http://www.ratundtat.com/index01.htm?menue=40, it's not oss but it 
> didn't look entirely impossible to create something similar.) and I 
> couldn't help dreaming about a common GUI description language that 
> could result into both Swing and Woody based apps...


And SWT... Some of my current wild thoughts is to use Woody and 
flowscript to build Eclipse plugins. Imagine every component coming with 
its own Woody form and associated flowscript and binding : building a 
Cocoon IDE for Eclipse can become quite easy.

> From that angle: being able to share your event-controllers might make 
> sense (although wrapping them inside specific listener interfaces 
> should not be that hard) 


Sorry, don't understand: what are "event-controllers" ?

>> This morning, I was reading an article about JavaServerFaces (never 
>> did look at it before), digged a bit, and discovered that what I was 
>> doing was very close to JSF event handling, and grabbed some 
>> interesting points. Digged further, and found the lifecycle thing 
>> very interesting, and once again close to the way Woody handles form 
>> processing. Parts of the JSF are not so bad and can be a good 
>> inspiration source ;-)
>
>
> I remember that Bruno had a look into the specs (and of the XForms) 
> when in the pre-woody phase (when the codename was still yaff) of 
> trying to nail down some initial design and try outs
>
> that together with the fact that we try to solve the same issues 
> porbably accounts for some 'similarities' 


Exactly. I also did read the XForms spec before comparing Woody and 
XMLForm back in August, and JSF, although complex and mixing concerns in 
the JSP, contains some interesting points in event handling and form 
processing lifecycle.

> I heard some good things about ASP.NET as well, and I remember 
> Carsten's  Dywel effort is inspired by his experience with webobjects: 
> there really is more inspiration out ther and I'm hoping some of this 
> inspiration will come together on the Hackathon-day 
> http://wiki.cocoondev.org/Wiki.jsp?page=GT2003Hackathon
> (suggestion: you (and Bruno) should ad yourself as an intro-speaker on 
> the topic, no?) 


Sure ! This topic should allow leave much room for participants to bring 
their respective experiences on the table. Examinging them to merge the 
good things into Woody is IMO a good way to have a strong form framework 
that satisfies everybody.

>> Once this infrastructure is in place, I plan to write specialized 
>> repeater-actions that automatically handle add/delete row in repeaters.
>>
>> More soon... 
>

Sylvain

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



Re: Event handling in Woody

Posted by Marc Portier <mp...@outerthought.org>.

Sylvain Wallez wrote:

> Hi all,
> 
> A short post to say that I've been working intensively on event handling 
> on Woody since yesterday. I'm nearly finished with it, and obtained 
> something powerful-yet-simple, that allows to define event handlers on 
> actions (ActionEvent) and fields (ValueChangeEvent). The goal is also to 

yoohoo!, looking forward.
in fact I thought about this from the start, but failed to explain to 
myself how it should look like (I also kept on mixing it up with 
client-side javascript)

care to textualize some preview on what goes about before we see the code?

also this links back to another wild idea I'm having
I'm still not quite satisfied with the way the repeater-binding (the not 
simple one) needs to operate for detecting new/deleted/syill-existing 
rows in the repeater...

So I hope the way you handle valuechanged can give some inspiration on 
how to mark the changed state of repeater rows?

BTW: I assume that the ValueChangedEvent is holding both the old and new 
value?

> allow event listeners to be written both in Java (classic-style) and in 
> JavaScript (flowscript-style).
> 

Makes sense.

I guess reusing the awt eventhandling interfaces is out of the question?
Not that I would consider it as a breaking design point to start using 
it, but yesterday someone showed me usage of jbeaver (see at 
http://www.ratundtat.com/index01.htm?menue=40, it's not oss but it 
didn't look entirely impossible to create something similar.) and I 
couldn't help dreaming about a common GUI description language that 
could result into both Swing and Woody based apps...

 From that angle: being able to share your event-controllers might make 
sense (although wrapping them inside specific listener interfaces should 
not be that hard)

> This morning, I was reading an article about JavaServerFaces (never did 
> look at it before), digged a bit, and discovered that what I was doing 
> was very close to JSF event handling, and grabbed some interesting 
> points. Digged further, and found the lifecycle thing very interesting, 
> and once again close to the way Woody handles form processing. Parts of 
> the JSF are not so bad and can be a good inspiration source ;-)
> 

I remember that Bruno had a look into the specs (and of the XForms) when 
in the pre-woody phase (when the codename was still yaff) of trying to 
nail down some initial design and try outs

that together with the fact that we try to solve the same issues 
porbably accounts for some 'similarities'

I heard some good things about ASP.NET as well, and I remember Carsten's 
  Dywel effort is inspired by his experience with webobjects: there 
really is more inspiration out ther and I'm hoping some of this 
inspiration will come together on the Hackathon-day 
http://wiki.cocoondev.org/Wiki.jsp?page=GT2003Hackathon
(suggestion: you (and Bruno) should ad yourself as an intro-speaker on 
the topic, no?)

> Once this infrastructure is in place, I plan to write specialized 
> repeater-actions that automatically handle add/delete row in repeaters.
> 
> More soon...
> 

keep going :-)

-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org