Wiki source code of ERPrototaculous

Version 284.1 by Ravi Mendis on 2009/07/17 02:03

Hide last authors
Ravi Mendis 100.1 1 == Introduction ==
2
Ravi Mendis 209.1 3 ERPrototaculous was developed to provide the ajax functionality in ERDivaLook.
4
5 === What is ERPrototaculous? ===
6
Ravi Mendis 233.1 7 Features include:
Ravi Mendis 209.1 8
Ravi Mendis 233.1 9 * 'Organic' support for Prototype and Scriptaculous in WebObjects.
Ravi Mendis 283.1 10 ** Light-weight dynamic elements to support Prototype
11 ** No custom patches to Prototype
12 ** Sans the need to extend Prototype
Ravi Mendis 261.1 13 * Use of [[Unobtrusive Javascript>>http://en.wikipedia.org/wiki/Unobtrusive_JavaScript]].
14 * Pseudo-stateless ajax responses
Ravi Mendis 245.1 15 * A set of widgets in the Prototype + Scriptaculous family.
Ravi Mendis 233.1 16
17 ==== Unobtrusive Javascript in ERPrototaculous ====
18
19 Unobtrusive javascript is used in contrast to on-demand style of ajax programming.
Ravi Mendis 283.1 20 By including Javascript as well as CSS globally in the page wrapper, CSS and Javascript don't have to load inside each and every ajax requests.
21 This keeps the ajax responses compact and granular.
Ravi Mendis 233.1 22
Ravi Mendis 283.1 23 The result is **faster** and more **reliable** ajax in WebObjects.
Ravi Mendis 233.1 24
Ravi Mendis 259.1 25 ==== Prototype WebObjects Elements ====
Ravi Mendis 253.1 26
Ravi Mendis 259.1 27 ##Ajax.Updater## and ##Ajax.Request## have been implemented as WebObjects dynamic elements.
28
Ravi Mendis 253.1 29 ===== Ajax.Updater =====
30
31 Support for Prototype's [[Ajax.Updater>>http://www.prototypejs.org/api/ajax/updater]] is in the form of three components:
32
Ravi Mendis 261.1 33 * AjaxUpdaterLink
34 * AjaxUpdaterButton
35 * AjaxUpdaterForm (with ##onsubmit## for ajax form submission)
Ravi Mendis 253.1 36
Ravi Mendis 283.1 37 These components will update a **container** on the page:
Ravi Mendis 261.1 38
Ravi Mendis 283.1 39 {{code value="javascript"}}
40
41 new Ajax.Updater('container', url, {options});
42
43 {{/code}}
44
Ravi Mendis 261.1 45 ===== Ajax.Request =====
46
47 Prototype's [[Ajax.Request>>http://www.prototypejs.org/api/ajax/request]] is in the form of:
48
49 * AjaxRequestLink
50 * AjaxRequestButton
51
Ravi Mendis 283.1 52 These are used for strictly **background** ajax communication:
Ravi Mendis 261.1 53
Ravi Mendis 283.1 54 {{code value="javascript"}}
55
56 new Ajax.Request(url, {options});
57
58 {{/code}}
59
Ravi Mendis 229.1 60 ==== Prototype + Scriptaculous Widgets ====
Ravi Mendis 211.1 61
Ravi Mendis 209.1 62 * Accordion
63 * LightWindow
64 * ModalBox
65 * CalendarDateSelect
66 * FileUpload
Ravi Mendis 233.1 67
68 == Forms in ERPrototaculous ==
69
70 Differences from using forms in WebObjects. i.e ##WOForm##:
71
Ravi Mendis 261.1 72 1. All form controls must be named. This includes text fields, selects and buttons.
Ravi Mendis 233.1 73 (WebObjects dynamically assigned names are not compatible with ERPrototaculous).
Ravi Mendis 261.1 74 1. All forms in an ERPrototaculous app are instances of ##AjaxUpdaterForm##.
Ravi Mendis 283.1 75 1. Form submit buttons can be the form of a:
Ravi Mendis 261.1 76
77 *
Ravi Mendis 283.1 78 ** Static ##<button>##.
79 ** WOSubmitButton (if the result is to update whole page/app).
Ravi Mendis 233.1 80 ** AjaxUpdaterButton (to update a **container**). Or
Ravi Mendis 283.1 81 ** AjaxRequestButton (for a **background** ajax request).
Ravi Mendis 261.1 82
83 == Ajax Page Caching in ERPrototaculous ==
84
85 One notable difference in the ERPrototaculous and Ajax.framework is in the ajax responses.
Ravi Mendis 283.1 86 In ERPrototaculous, updates and actions break with "The WebObjects Way" by being pseudo-stateless.
Ravi Mendis 261.1 87
Ravi Mendis 283.1 88 Instead of returning a fresh response, an ajax update just returns the same (instance of the) page fragment.
Ravi Mendis 261.1 89
Ravi Mendis 283.1 90 The reason returning a fresh response is not necessary is because a client never travels back or forwards through the ajax application history - unlike in a typical WebObjects app.
91 Here the current state of the page fragment is all that is necessary.
92
93 == Actions in ERPrototaculous ==
94
95 Typically, in a WebObjects application, an action would return the contents of the entire page.
96
97 Ajax responses are typically page fragments or part of a page.
98 So you should make sure the actions in ERPrototaculous (or AjaxUpdaterButton and AjaxRequestButton) return the proper page fragment as opposed to the entire page.
99 This breaks with WO-tradition, so this is where you need to be careful.
100
101 {{note title="Actions"}}
102
103 ERPrototaculous actions *differ* from Ajax.framework actions - _They must return only the page fragment_.
104
105 {{/note}}
106
107 To assist with page fragments inside **forms**, you can make your ajax action responses a subclass of **WXPageFragment** (a utility to handle the forms processing between Prototype and WebObjects).