Wiki source code of ERPrototaculous
Version 117.1 by Ravi Mendis on 2010/03/01 17:07
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
100.1 | 1 | == Introduction == |
2 | |||
3 | ERPrototaculous was developed to provide the ajax functionality in ERDivaLook. | ||
4 | |||
5 | === What is ERPrototaculous? === | ||
6 | |||
7 | Features include: | ||
8 | |||
![]() |
114.1 | 9 | * 'Organic' support for Prototype and Scriptaculous in WebObjects. |
![]() |
100.1 | 10 | ** Light-weight dynamic elements to support Prototype |
![]() |
116.1 | 11 | ** Transparent API that don't hide or abstract Prototype and Scriptaculous |
![]() |
114.1 | 12 | ** No custom patches to Prototype |
13 | ** Sans extensions to Prototype | ||
![]() |
100.1 | 14 | * Use of [[Unobtrusive Javascript>>http://en.wikipedia.org/wiki/Unobtrusive_JavaScript]]. |
15 | * Pseudo-stateless ajax responses | ||
16 | * A set of widgets in the Prototype + Scriptaculous family. | ||
17 | |||
18 | ==== Unobtrusive Javascript in ERPrototaculous ==== | ||
19 | |||
20 | Unobtrusive javascript is used in contrast to on-demand style of ajax programming. | ||
21 | 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. | ||
22 | This keeps the ajax responses compact and simple. | ||
23 | |||
24 | The result is **faster** and more **reliable** ajax in WebObjects. | ||
25 | |||
26 | ==== Prototype WebObjects Elements ==== | ||
27 | |||
28 | ##Ajax.Updater## and ##Ajax.Request## have been implemented as WebObjects elements. | ||
29 | |||
30 | ===== Ajax.Updater ===== | ||
31 | |||
32 | Support for Prototype's [[Ajax.Updater>>http://www.prototypejs.org/api/ajax/updater]] is in the form of three elements: | ||
33 | |||
34 | * AjaxUpdaterLink | ||
35 | * AjaxUpdaterButton | ||
36 | * AjaxUpdaterForm (with ##onsubmit## for ajax form submission) | ||
37 | |||
38 | These components will update //any// **container** on the page: | ||
39 | |||
40 | {{code value="javascript"}} | ||
41 | |||
42 | new Ajax.Updater('container', url, {options}); | ||
43 | |||
44 | {{/code}} | ||
45 | |||
46 | ===== Ajax.Request ===== | ||
47 | |||
48 | Prototype's [[Ajax.Request>>http://www.prototypejs.org/api/ajax/request]] is in the form of: | ||
49 | |||
50 | * AjaxRequestLink | ||
51 | * AjaxRequestButton | ||
52 | |||
53 | These are used for strictly **background** ajax communication: | ||
54 | |||
55 | {{code value="javascript"}} | ||
56 | |||
57 | new Ajax.Request(url, {options}); | ||
58 | |||
59 | {{/code}} | ||
60 | |||
61 | ==== Prototype + Scriptaculous Widgets ==== | ||
62 | |||
63 | * Accordion | ||
64 | * LightWindow | ||
65 | * ModalBox | ||
66 | * CalendarDateSelect | ||
![]() |
114.1 | 67 | * FileUpload |
![]() |
100.1 | 68 | |
69 | Support for these widgets have been similarly implemented as **button** and **link** variants, depending whether it is used inside a form or not. | ||
70 | |||
71 | == Ajax Forms in ERPrototaculous == | ||
72 | |||
73 | Differences from using forms in WebObjects. i.e ##WOForm##: | ||
74 | |||
75 | 1. All ajax form controls must be named. This includes text fields, selects and buttons. | ||
76 | (WebObjects dynamically assigned names are not compatible with ERPrototaculous). | ||
77 | 1. All ajax forms in an ERPrototaculous app need to be instances of ##AjaxUpdaterForm##. | ||
78 | 1. Ajax form submit buttons can be a: | ||
79 | 1*. Static ##<button>##. | ||
80 | 1*. WOSubmitButton (if the result is to update whole page/app). | ||
81 | 1*. AjaxUpdaterButton (to update a **container**). Or | ||
82 | 1*. AjaxRequestButton (for a **background** ajax request). | ||
83 | |||
84 | So forms are different in Ajax.framework and ERPrototaculous. | ||
85 | |||
86 | In ERPrototaculous you may still have typical WebObjects forms (i.e WOForm) as well as use ajax forms (i.e **AjaxUpdaterForm**). | ||
87 | They behave differently in that an AjaxUpdaterForm will update the contents of a container as opposed to the entire page. | ||
88 | |||
89 | {{warning title="Warning"}} | ||
90 | |||
91 | You must *name your form controls*, otherwise under certain circumstances Prototype (ajax) form submission will break. | ||
92 | |||
93 | {{/warning}} | ||
94 | |||
![]() |
114.1 | 95 | == Ajax Response Handling in ERPrototaculous == |
![]() |
100.1 | 96 | |
![]() |
114.1 | 97 | One notable difference between the ERPrototaculous and Ajax frameworks is in the way they handle ajax responses. |
![]() |
100.1 | 98 | In ERPrototaculous, updates and actions break with //The WebObjects Way// by being pseudo-stateless. |
99 | |||
100 | In a typical WebObjects application, when a user navigates to the previous page using the browser back button and subsequently clicks on a link in on that page, WebObjects needs to remember how to handle that action and to return the correct page. This is no longer necessary for ajax. | ||
101 | |||
102 | A user never travels backwards or forwards through the ajax application history. | ||
103 | (i.e there is no forward/back buttons for ajax requests - just as there aren't forward/back buttons on desktop apps). | ||
104 | |||
105 | So for ajax, the current state of the page fragment component is all that is necessary. | ||
106 | |||
107 | {{info title="No More"}} | ||
108 | |||
109 | A 100% ajax WO-app (like an [ERDivaLook|ERDivaLook] app) is no longer plagued by the well known _limitation_ of WebObjects - the browser *backtrack problem*. | ||
110 | |||
111 | {{/info}} | ||
112 | |||
113 | == Ajax Actions in ERPrototaculous == | ||
114 | |||
115 | Typically, in a WebObjects application, an action would return the contents of the entire page. | ||
116 | |||
117 | Ajax responses are mostly page fragments or just part of a page. | ||
118 | So you should make sure the actions in ERPrototaculous (or AjaxUpdaterButton and AjaxRequestButton) return the proper page fragment as opposed to the entire page. | ||
![]() |
114.1 | 119 | This breaks with WO-tradition (again), so this is where you need to be careful. |
![]() |
100.1 | 120 | |
121 | {{note title="Note"}} | ||
122 | |||
123 | ERPrototaculous actions *differ* from Ajax.framework actions - _They must return only the page fragment_. | ||
124 | |||
125 | {{/note}} | ||
126 | |||
127 | 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). | ||
128 | |||
129 | == Update Containers in ERPrototaculous == | ||
130 | |||
131 | Perhaps the only real similarity to Ajax.framework is the ajax update container. | ||
132 | **WXGenericContainer** is the ERPrototaculous update container. | ||
133 | It is similar to an AjaxUpdateContainer when it has the binding ##ajax = true##, otherwise it's pretty much like **WOGenericContainer**. | ||
134 | |||
135 | It has been implemented as a utility or //convenience// for Prototype's ##Ajax.Updater##. | ||
136 | That is it can be used to update from a DOM //event// like popup //onchange//, or from a Prototype //callback// like //onComplete//, etc. | ||
137 | |||
138 | == Compatibility == | ||
139 | |||
140 | ERPrototaculous can not be used with WebObjects 5.3 as it is dependent on the hooks for ajax added to WebObjects with version 5.4. | ||
141 | |||
142 | {{warning title="ERPrototaculous is WebObjects *5.4* compatible only"}} | ||
143 | |||
144 | |||
145 | {{/warning}} |