WebObjects/Web Applications/Development/How Forms Work

This document was written by Andrew Lindesay (http://www.lindesay.co.nz) and relates to WebObjects 5.3.

Overview
Component actions work by utilising the latter end of the action URL which will look something like 2.12.6.2 to allow the element which "owns" the action to invoke its bound action method. We call the inbound numerical string the "sender id" and the identifier of the element, the "element id". If the two match up then the element knows it should invoke its action.

If you have a form with many submit buttons this cannot be how the right action gets invoked because the action method contains a URL with a "sender id" of the form. This won't match with the "element id" of the submit button. For example, the following fictitious code illustrates this.

  

The submit button here might have element ID of 32.0.2, but the form has element 0.32.0. So it will not be possible to match up the sender id with the element id. So the question is; how does this mechanism work?

Invoke Action
The submit button could look for a value of 32.0.2 in the inbound request. In this way it would be able to see the value Search and then invoke the bound action. However this mechanism is slightly more complex. The form element makes modifications to the context in order to get the submit buttons to exhibit this behaviour. Those modifications include setting the  method as well as some internal methods to state if the form was submitted and if a submit button has invoked its action method yet.

If the submit button does invoke its method then it in turn modifies the context to state that an action had been "fired". If no submit button does set this value in the context then the form can invoke its own action method if appropriate.

Append To Response
The WOForm simply sets into the context that it is in a form and then renders its children.

Take Values From Request
The WOForm sets into the context that the children are in a form and if the form was submitted and then allows its children elements to take their values from the request.