Last modified by Pascal Robert on 2007/09/03 20:53

From version 11.1
edited by smmccraw
on 2007/07/08 09:43
Change comment: There is no comment for this version
To version 12.1
edited by Pascal Robert
on 2007/09/03 20:53
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Programming__WebObjects-Alternative Technologies-Ruby on Rails
1 +Alternative Technologies-Ruby on Rails
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.smmccraw
1 +XWiki.probert
Content
... ... @@ -1,75 +1,76 @@
1 -=== Pierce T. Wetter III ===
1 +=== Pierce T. Wetter III ===
2 2  
3 -==== Myth: Rails is a better framework for Ajax than WO. ====
3 +==== Myth: Rails is a better framework for Ajax than WO. ====
4 4  
5 5  Reality: WebObjects is actually a better framework for use with Ajax libraries than Rails because it has a better component system than Rails. You spend a lot of time coding little tiny XML and HTML generators when doing Ajax and WO's component system makes that very DRY (Don't Repeat Yourself).
6 6  
7 -==== Myth: WebObjects is hard to use with Ajax. ====
7 +==== Myth: WebObjects is hard to use with Ajax. ====
8 8  
9 9  Reality: WebObjects is easy to use with Ajax, it's just that there is only one known library for Ajax-WO support, and its not well documented. Even then the library only goes so far in that it just provides new components to wrap a few script.aculo.us tags. I think its more of a documentation gap, not a code gap.
10 10  
11 11  Additionally, the WO documentation has always pushed people erroneously towards component actions and away from direct actions. If you use 90% direct actions like I do in my application, (See my "WebObjects on Rails" post), you'll find that direct actions are simple to code in reality, and very much like Rails which basically doesn't have component actions at all.
12 12  
13 -//[[Which is to say, if you avoid much of the power of WO, and don't use component actions, ajax will be easier. If you do use component actions - and I have yet to work on a project that doesn't - then ajax use seems like it will blow your page cache, as described below. So it really is easy to use AJAX in WO. Really easy. It's just that it doesn't work]]//
13 +//Which is to say, if you avoid much of the power of WO, and don't use component actions, ajax will be easier. If you do use component actions - and I have yet to work on a project that doesn't - then ajax use seems like it will blow your page cache, as described below. So it really is easy to use AJAX in WO. Really easy. It's just that it doesn't work.//
14 14  
15 -//[[mschrag: While I agree with the above commenter that component actions provide a huge amount of power in WO, it is NOT true that Ajax and component actions are incompatible. ~[Project Wonder's Ajax components>>Programming__WebObjects-Project_WONDER-Frameworks-Ajax]] directly addresses the use of component actions with Ajax in a way that does NOT blow the page cache. While it is true that the implementation of these capabilities inside of Wonder was non-trivial, it demonstrates that it is, in fact, possible, and if you use the PW components along with ERXSession, you will get this capability for free.]//
15 +//mschrag: While I agree with the above commenter that component actions provide a huge amount of power in WO, it is NOT true that Ajax and component actions are incompatible.// //[[//Project Wonder's Ajax components//>>Programming__WebObjects-Project_WONDER-Frameworks-Ajax]]// //directly addresses the use of component actions with Ajax in a way that does NOT blow the page cache. While it is true that the implementation of these capabilities inside of Wonder was non-trivial, it demonstrates that it is, in fact, possible, and if you use the PW components along with ERXSession, you will get this capability for free.//
16 16  
17 -==== Myth: You can't assign the name or id value of tags in WebObjects. ====
17 +==== Myth: You can't assign the name or id value of tags in WebObjects. ====
18 18  
19 19  I'm mentioning this one explicitly, because I had someone ask me about this recently, because they were trying to assign a WYSIWYG JavaScript editor to a text area.
20 20  
21 21  Reality: Actually, what really happens is that if you DON'T have a name=value or id=value line for your TextArea in WebObjects, it will generate a unique one for you. But you're more than welcome to specify one in your .wod file, and WO will use that. It's then up to //you// to make sure its unique, so that you don't have multiple text area tags with the same name. In other words if you only have one textarea you wish to attach a Javascript WYSIWYG editor to, just add:
22 22  
23 -{{panel}}
23 +{{code}}
24 24  
25 - textarea: WOText
26 - {
27 - id='wysiwyg';
28 - name='wysiwyg';
29 - value=textValue;
30 - }
25 +textarea: WOText
26 +{
27 + id='wysiwyg';
28 + name='wysiwyg';
29 + value=textValue;
30 +}
31 31  
32 -{{/panel}}
32 +{{/code}}
33 33  
34 34  in your .wod file and you can use id with your Javascript just fine.
35 35  
36 -==== Myth: WebObjects generates HTML ====
36 +==== Myth: WebObjects generates HTML ====
37 37  
38 38  Reality: Just because the components of your .wo file are .html and .wod doesn't mean WebObjects can only generate HTML. WebObjects is really at heart, a very, very, very, complicated printf. The result of a component can be HTML, XML, JavaScript, or even binary data. You can actually put whatever you want in the .HTML and treat WebObjects like a giant merge engine. For instance, you could generate PDF files using WebObjects; they're just text, and you could substitute text into the middle of the PDF boilerplate pretty easily.
39 39  
40 -==== Background ====
40 +==== Background ====
41 41  
42 42  We haven't used a lot of JavaScript at www.marketocracy.com, for a very simple reason: We don't have the testing staff to fire up 10 different browser variations to test the site. And lets face it, programming in JavaScript sucks.
43 43  
44 -Since someone invented that cool acronym though, that's changing. You would think it shouldn't matter that something has a name, but it does. I remember when the GoF Design Patterns book came out. There was nothing in there I hadn't figured out on my own, but now they had a name!//I//could//say//"Singleton"//to//my//co-workers//and//they//would//know//what//I//was//talking//about.//I//could//buy//a//junior//engineer//the//book,//and//he//would//soon//be//programming//at//a//much//higher//level.//
44 +Since someone invented that cool acronym though, that's changing. You would think it shouldn't matter that something has a name, but it does. I remember when the GoF Design Patterns book came out. There was nothing in there I hadn't figured out on my own, but now they had a name I could say "Singleton" to my co-workers and they would know what I was talking about. I could buy a junior engineer the book, and he would soon be programming at a much higher level.
45 45  
46 -So//having//a//name//helped,//and//the//result//is//that//there//are//a//lot//of//cool//toolkits//out//there.//Since//someone//else//wrote//the//JavaScript,//that//means//I//don't//need//to//test//10//different//browser//variations.//
46 +So having a name helped, and the result is that there are a lot of cool toolkits out there. Since someone else wrote the JavaScript, that means I don't need to test 10 different browser variations.
47 47  
48 -Which//means//I//can//make//the//site//much//easier//to//use//and//more//interactive.//Huzzah!
48 +Which means I can make the site much easier to use and more interactive. Huzzah
49 49  
50 -==== Research ====
50 +==== Research ====
51 51  
52 52  So the first thing I did was that I'd heard that Rails was cool and made Ajax easy. I'd heard that before, but that was when the version number was 0.13... So I went out and bought the Rails books and you know what I found?
53 53  
54 54  It's not that Rails rocks with Ajax, its that the Prototype Javascript library rocks. The documentation makes a big deal about doing Ajax with one line of code.
55 55  
56 -{{panel}}
56 +{{code value="xml"}}
57 57  
58 - <div id='<= posting.id'>
59 - <%= link_to_remote [div to update] [link options] -> %>
60 - </div>
58 +<div id='<= posting.id'>
59 + <%= link_to_remote [div to update] [link options] -> %>
60 +</div>
61 61  
62 -{{/panel}}
62 +{{/code}}
63 63  
64 64  The reality is that all Rails is doing is writing one line of JavaScript. From the Ajaxy "rating" code I've been adding to my app, look at the following:
65 65  
66 -{{panel}}
66 +{{code value="xml"}}
67 67  
68 - <div id='<WEBOBJECT name=postingID></WEBBOBJECT>'>
69 - <a href="#" onclick="new Ajax.Updater('<WEBOBJECT name=postingID></WEBBOBJECT>', '<WEBOBJECT name=ratePosting></WEBOBJECT>', {asynchronous:true, evalScripts:true}); return false;">1</a>
70 - </div>
68 +<div id='<WEBOBJECT name=postingID></WEBBOBJECT>'>
69 + <a href="#" onclick="new Ajax.Updater('<WEBOBJECT name=postingID></WEBBOBJECT>',
70 + '<WEBOBJECT name=ratePosting></WEBOBJECT>', {asynchronous:true, evalScripts:true}); return false;">1</a>
71 +</div>
71 71  
72 -{{/panel}}
73 +{{/code}}
73 73  
74 74  Ok, so lets break it down. The way Ajax.Updater works from the Prototype library is you give it the id of a DOM object and a URL, and it replaces the DOM object with that id with the contents of the URL. Usually, you specify the area to update with a div tag which I've shown for completeness. For ratings I would need 1 div tag to enclose all 5 rating stars: <div><a></a><a></a><a></a><a></a><a></a></div>. I would also use a WOGenericContainer to generate the div tag with the right id rather than using the id='<WEBOBJECT name=postingID></WEBBOBJECT>' line, but I wanted it to be obvious it was div tag.
75 75  
... ... @@ -77,67 +77,67 @@
77 77  
78 78  Here I have a manually built <a> tag with an onclick bit of javascript. That makes a single call out to the Prototype library, which has this cool call:
79 79  
80 -{{panel}}
81 +{{code}}
81 81  
82 - new Ajax.Updater( elementid, url, options)
83 +new Ajax.Updater( elementid, url, options)
83 83  
84 -{{/panel}}
85 +{{/code}}
85 85  
86 86  It does something very simple: It pulls the HTML from the specified URL, and replaces the element with the specified id with the downloaded HTML.
87 87  
88 88  The two WebObjects tags specify the element ID and the link, they're just a WOString and a WOActionURL:
89 89  
90 -{{panel}}
91 +{{code}}
91 91  
92 - postingID: WOString { currentPosting.primaryKeyString; }
93 - ratePosting: WOActionURL { see discussion }
93 +postingID: WOString { currentPosting.primaryKeyString; }
94 +ratePosting: WOActionURL { see discussion }
94 94  
95 -{{/panel}}
96 +{{/code}}
96 96  
97 97  Now in my case, I'm a direct action snob. So my WOActionURL would look like the following:
98 98  
99 -{{panel}}
100 +{{code}}
100 100  
101 - ratePosting :WOActionURL
102 - {
103 - directActionName="PostingRater";
104 - ?pkey=currentPosting.primaryKey;
105 - ?rating=cRating;
106 - ?wosid=NO;
107 - }
102 +ratePosting :WOActionURL
103 +{
104 + directActionName="PostingRater";
105 + ?pkey=currentPosting.primaryKey;
106 + ?rating=cRating;
107 + ?wosid=NO;
108 +}
108 108  
109 -{{/panel}}
110 +{{/code}}
110 110  
111 111  This produces a result similar to Rails, because in rails you have to define an action for each class of link. In my case I tie directactions to pages/components, so my "PostingRater" page would return component-level HTML (minus any HEAD/BODY tags) that matched the existing <div> definition. Since we're using WebObjects, that turns out to be trivially easy if we build the enclosing <div> tag with a component PostingRater can just look like:
112 112  
113 -{{panel}}
114 +{{code value="xml"}}
114 114  
115 - <WEBOBJECT name=RatingDiv></WEBOBJECT>
116 +<WEBOBJECT name=RatingDiv></WEBOBJECT>
116 116  
117 -{{/panel}}
118 +{{/code}}
118 118  
119 119  Using component actions, it could be even simpler:
120 120  
121 -{{panel}}
122 +{{code}}
122 122  
123 - ratePosting: WOActionURL { action=ratePosting;}
124 +ratePosting: WOActionURL { action=ratePosting;}
124 124  
125 -{{/panel}}
126 +{{/code}}
126 126  
127 127  Because WebObjects, unlike Rails can have stateful components, the RatingDiv component could actually have all the logic and return self as the result of the action:
128 128  
129 -{{panel}}
130 +{{code}}
130 130  
131 - public WOReponse ratePosting
132 - {
133 - currentPosting.ratePosting(currentRating);
134 - return self; // since this is called from JavaScript
135 - // return just myself, not self.page
136 - // this will tell WO to render only
137 - // this as a result.
138 - }
132 +public WOReponse ratePosting
133 +{
134 + currentPosting.ratePosting(currentRating);
135 + return self; // since this is called from JavaScript
136 + // return just myself, not self.page
137 + // this will tell WO to render only
138 + // this as a result.
139 +}
139 139  
140 -{{/panel}}
141 +{{/code}}
141 141  
142 142  That is, the link for the javascript would go into the RatingDiv component with everything already setup: the current posting, the current rating. Returning self then causes the div to regenerate.
143 143  
... ... @@ -153,11 +153,11 @@
153 153  
154 154  I also think, that from this example, dojo is a bit weak as a Javascript toolkit. You'll spend a lot of time wiring stuff up in Javascript with Dojo compared to Prototype. Or contrast dojo with the Yahoo UI library:
155 155  
156 -http:~/~/developer.yahoo.com/yui/
157 +[[http://developer.yahoo.com/yui/]]
157 157  
158 158  The whole "Dialog" thing in yui is cool:
159 159  
160 -http:~/~/developer.yahoo.com/yui/container/dialog/index.html
161 +[[http://developer.yahoo.com/yui/container/dialog/index.html]]
161 161  
162 162  And would lend itself quite readily to the model WO has of building pages out of pieces.
163 163  
... ... @@ -164,5 +164,3 @@
164 164  Then again, dojo is only at version 0.3. The WYSIWYG editor is nice, but I really don't want to have to define my dialog boxes in yet another tag language. HTML is good enough for me.
165 165  
166 166  So exactly what problems are you having with dojo/wo? Consider that the problem may be dojo, not WO in particular. You could easily create a WODynamicElement for every new dojo tag, collect them in components, and have something much easier to use than straight dojo.
167 -
168 -Category:WebObjects