Wiki source code of D2W Rules Reference - Cookbook - FAQ
Version 84.1 by Johan Henselmans on 2011/04/19 16:05
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | === Rule Lists === | ||
| 2 | |||
| 3 | Below are some commonly used rules and information on keys which control D2W templates. You may wish to keep your own library of commonly used D2W rules, something like "D2WRuleLibrary.d2wmodel", which can then be used to copy and paste rules into your projects. | ||
| 4 | |||
| 5 | ==== For quick reference: ==== | ||
| 6 | |||
| 7 | ~1. How do I make my attributes and entities editable? | ||
| 8 | |||
| 9 | {{noformat}} | ||
| 10 | |||
| 11 | 100: true => isEntityEditable = true [com.webobjects.directtoweb.BooleanAssignment] | ||
| 12 | |||
| 13 | |||
| 14 | {{/noformat}} | ||
| 15 | |||
| 16 | 2. How do I make my relationships editable in ERD2W? (They are already are editable in D2W.) | ||
| 17 | Add two rules. This: | ||
| 18 | |||
| 19 | {{noformat}} | ||
| 20 | |||
| 21 | 90: task = 'edit' and smartRelationship.isToMany = 1 => componentName = "ERD2WEditToManyFault" | ||
| 22 | [com.webobjects.directtoweb.Assignment] | ||
| 23 | |||
| 24 | |||
| 25 | {{/noformat}} | ||
| 26 | |||
| 27 | and the below: | ||
| 28 | |||
| 29 | {{noformat}} | ||
| 30 | |||
| 31 | 90: task = 'edit' and smartRelationship != null and not (smartRelationship.isToMany = 1) => componentName = "ERD2WEditToOneRelationship" | ||
| 32 | [com.webobjects.directtoweb.Assignment] | ||
| 33 | |||
| 34 | |||
| 35 | {{/noformat}} | ||
| 36 | |||
| 37 | 3. Similarly how do I make my relationships display nicely in an Inspect page in ERD2W? By default they show up as an array fault. | ||
| 38 | There are many possible components to choose from. These are just a couple as an example. | ||
| 39 | Add two rules. This: | ||
| 40 | |||
| 41 | {{noformat}} | ||
| 42 | |||
| 43 | 90: task = 'inspect' and smartRelationship.isToMany = 1 => componentName = "ERD2WDisplayToManyList" | ||
| 44 | [com.webobjects.directtoweb.Assignment] | ||
| 45 | |||
| 46 | |||
| 47 | {{/noformat}} | ||
| 48 | |||
| 49 | and the below: | ||
| 50 | |||
| 51 | {{noformat}} | ||
| 52 | |||
| 53 | 90: task = 'inspect' and smartRelationship != null and not (smartRelationship.isToMany = 1) => componentName = "ERD2WDisplayToOne" | ||
| 54 | [com.webobjects.directtoweb.Assignment] | ||
| 55 | |||
| 56 | |||
| 57 | {{/noformat}} | ||
| 58 | |||
| 59 | 4. I don't like the defaults for attributes that D2W chooses. Sometimes it chooses wisely, but not always. How do I change what gets displayed for an entity's attributes? | ||
| 60 | |||
| 61 | The key is: displayPropertyKeys. This key represents a list of attributes to display for an entity. An example rule: | ||
| 62 | |||
| 63 | {{noformat}} | ||
| 64 | |||
| 65 | 100: entity.name = 'MyEntity' => displayPropertyKeys = ("attribute1","attribute2", "relationship1","relationship2.attribute3") [Assignment] | ||
| 66 | |||
| 67 | |||
| 68 | {{/noformat}} | ||
| 69 | |||
| 70 | Note that you can pick attributes across relationships. You now have total control of what gets displayed. | ||
| 71 | |||
| 72 | 5. If you want to use [[WOL:Click to Open]] for your D2W project, you'll need to disable it when you are generating ERExcelLook pages or the resulting Excel file will be unreadable gibberish. | ||
| 73 | |||
| 74 | The key is: clickToOpenEnabled. This key is on ERD2WPage and controls whether clickToOpen is enabled for that specific page. An example rule: | ||
| 75 | |||
| 76 | {{noformat}} | ||
| 77 | |||
| 78 | 10 : pageConfiguration like '*Excel*' => clickToOpenEnabled = false [com.webobjects.directtoweb.BooleanAssignment] | ||
| 79 | |||
| 80 | |||
| 81 | {{/noformat}} | ||
| 82 | |||
| 83 | 6. How do I control the list of visible Entities in my PageWrapper? My select entity popup is showing entities I don't want to be visible (ERAttachment, Lookup values, etc). | ||
| 84 | |||
| 85 | {{noformat}} | ||
| 86 | |||
| 87 | 100: *true* => visibleEntityNames = ("Foo","Bar","Baz","FooBar") [Assignment] | ||
| 88 | |||
| 89 | |||
| 90 | {{/noformat}} | ||
| 91 | |||
| 92 | 7. How do I easily use my own custom component in a Direct to Web page? | ||
| 93 | |||
| 94 | Step 1: | ||
| 95 | |||
| 96 | Add the following rules to your rule file: | ||
| 97 | |||
| 98 | {{noformat}} | ||
| 99 | |||
| 100 | 100: pageConfiguration = "ListTheEntity" and propertyKey = "theProperty" => componentName = "D2WCustomComponent" | ||
| 101 | 100: pageConfiguration = "ListTheEntity" and propertyKey = "theProperty" => customComponentName = "MyThePropertyComponent" | ||
| 102 | |||
| 103 | |||
| 104 | {{/noformat}} | ||
| 105 | |||
| 106 | Step 2: | ||
| 107 | |||
| 108 | Create a component in your project named 'MyThePropertyComponent' and give it an 'object' and 'key' binding. The object will receive the current object, and the key will receive the current propertyKey (as a string) from DirectToWeb. Do with them what you will. | ||
| 109 | |||
| 110 | {{code}} | ||
| 111 | |||
| 112 | public EOEnterpriseObject object() { | ||
| 113 | return (EOEnterpriseObject) valueForBinding("object"); | ||
| 114 | } | ||
| 115 | |||
| 116 | public String key() { | ||
| 117 | return (String) valueForBinding("key"); | ||
| 118 | } | ||
| 119 | |||
| 120 | {{/code}} | ||
| 121 | |||
| 122 | 8. How do I use features such as sections and tabs with the rules? | ||
| 123 | |||
| 124 | {{noformat}} | ||
| 125 | |||
| 126 | 100: (entity.name = 'Movie' and (task = 'inspect' or task = 'edit')) => subTask = "tab" | ||
| 127 | 100: (entity.name = 'Movie' and (task = 'inspect' or task = 'edit')) => tabSectionsContents = ( ("Foo", ("FooBar", "title", "category", "dateReleased"), ("FooBaz", "plotSummary", "posterName")), ("Bar", "revenue", "studio")) | ||
| 128 | |||
| 129 | |||
| 130 | {{/noformat}} | ||
| 131 | |||
| 132 | The second rule will give you: | ||
| 133 | |||
| 134 | Tabs: Foo, Bar | ||
| 135 | |||
| 136 | Sections under Foo: FooBar, FooBaz | ||
| 137 | |||
| 138 | Like: | ||
| 139 | |||
| 140 | FooBar | ||
| 141 | title | ||
| 142 | category | ||
| 143 | dateReleased | ||
| 144 | |||
| 145 | FooBaz | ||
| 146 | plotSummary | ||
| 147 | posterName | ||
| 148 | |||
| 149 | 9. A simpler way to specify this stuff is: | ||
| 150 | |||
| 151 | {{noformat}} | ||
| 152 | |||
| 153 | displayPropertyKeys = ("(section11)", "key11".... "(section2)", "key21") | ||
| 154 | |||
| 155 | and | ||
| 156 | |||
| 157 | displayPropertyKeys = ("[Tab1]", "(section11)", "key11".... "[Tab2]", "(section21)", "key21") | ||
| 158 | |||
| 159 | for tab pages. | ||
| 160 | |||
| 161 | {{/noformat}} | ||
| 162 | |||
| 163 | 10. Changing the display name for a PageConfiguration | ||
| 164 | |||
| 165 | You may want to use a Page Configuration Name that is consistent with the rules for your application (uses an EntityName), but it looks weird when it is parsed for display in the default way. | ||
| 166 | |||
| 167 | For example, in Bugtracker there is a page configuration named "EditMyPeople" which makes perfect sense for the rules, but not too much as an "Edit My Profile" page. The easy way around it is: | ||
| 168 | |||
| 169 | {{noformat}} | ||
| 170 | |||
| 171 | 100: (pageConfiguration = 'EditMyPeople' => displayNameForPageConfiguration = "Edit My Profile" | ||
| 172 | |||
| 173 | |||
| 174 | {{/noformat}} | ||
| 175 | |||
| 176 | However, it is better practice to get labels out of the rules altogether unless you want to make use of variables inside them. You put labels in your Localizable.strings file. If you just want plain text, no rule is necessary. For the following examples, "MyDocuments" is the pageConfigurationName. | ||
| 177 | |||
| 178 | {{noformat}} | ||
| 179 | |||
| 180 | Localizable.strings | ||
| 181 | "Pages.MyDocuments" = "List My Documents!"; | ||
| 182 | |||
| 183 | {{/noformat}} | ||
| 184 | |||
| 185 | This entry can be used with no associated rule and it will do the right thing. | ||
| 186 | |||
| 187 | If you want to use the @@session.variable.blah@@ in your pageConfigurationNames, you'll need to use a rule with a delayed assignment. | ||
| 188 | |||
| 189 | {{noformat}} | ||
| 190 | |||
| 191 | Localizable.strings | ||
| 192 | "Pages.MyDocuments" = "List @@session.loggedInUser.fullName@@'s Documents"; | ||
| 193 | |||
| 194 | Rule: | ||
| 195 | 100 : pageConfiguration = 'MyDocuments' => displayNameForPageConfiguration = "Pages.MyDocuments" [ERDDelayedLocalizedAssignment] | ||
| 196 | |||
| 197 | {{/noformat}} | ||
| 198 | |||
| 199 | === Adding a normal component to a ModernDirectToWeb App === | ||
| 200 | |||
| 201 | ==== ==== | ||
| 202 | |||
| 203 | Suppose you have a component somewhere that you would like to use to a direct To Web App as an extra option, under the tab section. How do get this component to work with the rest of the Direct To Web App? | ||
| 204 | |||
| 205 | The way to do this is described in some [[mails>>http://lists.apple.com/archives/webobjects-dev/2011/Mar/msg00366.html]] , but it took me some time to understand all the intricacies, so here it goes: | ||
| 206 | |||
| 207 | We have a component HelloWorld, that consist of the following contents: | ||
| 208 | |||
| 209 | ===== HelloWorld.wo: ===== | ||
| 210 | |||
| 211 | {{color value="#569191"}} | ||
| 212 | < | ||
| 213 | {{/color}} | ||
| 214 | |||
| 215 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 216 | |||
| 217 | What is your name?{{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOTextField{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[username]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 218 | |||
| 219 | {{color value="#569191"}} | ||
| 220 | < | ||
| 221 | {{/color}} | ||
| 222 | |||
| 223 | {{color value="#115454"}}wo:WOSubmitButton{{/color}} {{color value="#901291"}}action{{/color}}{{color value="#569191"}}={{/color}}{{color value="#c07212"}}"[fixUsername]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 224 | |||
| 225 | {{color value="#569191"}} | ||
| 226 | </ | ||
| 227 | {{/color}} | ||
| 228 | |||
| 229 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 230 | |||
| 231 | {{color value="#569191"}} | ||
| 232 | < | ||
| 233 | {{/color}} | ||
| 234 | |||
| 235 | {{color value="#115454"}}wo:WOConditional{{/color}} {{color value="#901291"}}condition{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[username]"{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 236 | |||
| 237 | {{color value="#000000"}} | ||
| 238 | Hello | ||
| 239 | {{/color}} | ||
| 240 | |||
| 241 | {{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOString{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[userNameExtended]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 242 | |||
| 243 | {{color value="#569191"}} | ||
| 244 | </ | ||
| 245 | {{/color}} | ||
| 246 | |||
| 247 | {{color value="#115454"}}wo:WOConditional{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 248 | |||
| 249 | ===== **HelloWorld.java** ===== | ||
| 250 | |||
| 251 | {{color value="#8f1069"}} | ||
| 252 | import | ||
| 253 | {{/color}} | ||
| 254 | |||
| 255 | com.webobjects.appserver.WOContext; | ||
| 256 | |||
| 257 | {{color value="#8f1069"}} | ||
| 258 | import | ||
| 259 | {{/color}} | ||
| 260 | |||
| 261 | er.extensions.components.ERXComponent; | ||
| 262 | \\ | ||
| 263 | |||
| 264 | {{color value="#8f1069"}} | ||
| 265 | public | ||
| 266 | {{/color}} | ||
| 267 | |||
| 268 | {{color value="#8f1069"}}class{{/color}} __HelloWorld__ {{color value="#8f1069"}}extends{{/color}} ERXComponent { | ||
| 269 | |||
| 270 | {{color value="#8f1069"}}private{{/color}} String {{color value="#2608ca"}}username{{/color}}; | ||
| 271 | |||
| 272 | {{color value="#8f1069"}}private{{/color}} {{color value="#000000"}}String{{/color}} {{color value="#2608ca"}}userNameExtended{{/color}}{{color value="#000000"}};{{/color}}\\ | ||
| 273 | |||
| 274 | {{color value="#8f1069"}}public{{/color}} HelloWorld(WOContext context) { | ||
| 275 | |||
| 276 | {{color value="#8f1069"}}super{{/color}}(context); | ||
| 277 | |||
| 278 | } | ||
| 279 | \\ | ||
| 280 | |||
| 281 | {{color value="#8f1069"}}public{{/color}} ERXComponent fixUserName() { | ||
| 282 | |||
| 283 | {{color value="#549172"}}//create a new component, which will be sent to the user with it's name appended{{/color}} | ||
| 284 | |||
| 285 | HelloWorld aPage = (HelloWorld) pageWithName({{color value="#4a0ffe"}}"HelloWorld"{{/color}}); | ||
| 286 | |||
| 287 | {{color value="#549172"}}// we do not like WOBers without the name{{/color}} {{color value="#549172"}}{+}David{+}{{/color}} | ||
| 288 | |||
| 289 | String extendedUserName={{color value="#4a0ffe"}}""{{/color}}; | ||
| 290 | |||
| 291 | {{color value="#8f1069"}}if{{/color}}(username()={{color value="#8f1069"}}null{{/color}}){ | ||
| 292 | |||
| 293 | {{color value="#000000"}} | ||
| 294 | | ||
| 295 | {{/color}} | ||
| 296 | |||
| 297 | {{color value="#000000"}}extendedUserName={{/color}}{{color value="#4a0ffe"}}"David-"{{/color}}{{color value="#000000"}}+username()+{{/color}}{{color value="#4a0ffe"}}"(There is no WOBber that doesn't have David in his firstname)"{{/color}}{{color value="#000000"}};{{/color}} | ||
| 298 | |||
| 299 | } {{color value="#8f1069"}}else{{/color}} { | ||
| 300 | |||
| 301 | extendedUserName={{color value="#4a0ffe"}}"Please fill in some name"{{/color}}; | ||
| 302 | |||
| 303 | } | ||
| 304 | |||
| 305 | {{color value="#000000"}} | ||
| 306 | | ||
| 307 | {{/color}} | ||
| 308 | |||
| 309 | {{color value="#549172"}}//set the User Name on the new page{{/color}} | ||
| 310 | |||
| 311 | aPage.setUserNameExtended(extendedUserName); | ||
| 312 | |||
| 313 | {{color value="#8f1069"}}return{{/color}} aPage; | ||
| 314 | |||
| 315 | } | ||
| 316 | |||
| 317 | {{color value="#8f1069"}}public{{/color}} String username() { | ||
| 318 | |||
| 319 | {{color value="#8f1069"}}return{{/color}} {{color value="#2608ca"}}username{{/color}}{{color value="#000000"}};{{/color}} | ||
| 320 | |||
| 321 | } | ||
| 322 | \\ | ||
| 323 | |||
| 324 | {{color value="#8f1069"}}public{{/color}} {{color value="#8f1069"}}void{{/color}} setUsername(String username) { | ||
| 325 | |||
| 326 | {{color value="#8f1069"}}this{{/color}}.{{color value="#2608ca"}}username{{/color}} = username; | ||
| 327 | |||
| 328 | } | ||
| 329 | \\ | ||
| 330 | |||
| 331 | {{color value="#8f1069"}}public{{/color}} String userNameExtended() { | ||
| 332 | |||
| 333 | {{color value="#8f1069"}}return{{/color}} {{color value="#2608ca"}}userNameExtended{{/color}}{{color value="#000000"}};{{/color}} | ||
| 334 | |||
| 335 | } | ||
| 336 | \\ | ||
| 337 | |||
| 338 | {{color value="#8f1069"}}public{{/color}} {{color value="#8f1069"}}void{{/color}} setUserNameExtended(String userNameExtended) { | ||
| 339 | |||
| 340 | {{color value="#8f1069"}}this{{/color}}.{{color value="#2608ca"}}userNameExtended{{/color}} = userNameExtended; | ||
| 341 | |||
| 342 | } | ||
| 343 | |||
| 344 | } | ||
| 345 | |||
| 346 | ~======================== | ||
| 347 | |||
| 348 | Normally, this Component will pickup a username, and will create a correct user name. | ||
| 349 | |||
| 350 | Now suppose we want to make this component a Direct To Web Component. | ||
| 351 | |||
| 352 | First I will do the obvious: | ||
| 353 | |||
| 354 | I will add the component to the NavigationMenu.plist: | ||
| 355 | |||
| 356 | {{code}} | ||
| 357 | |||
| 358 | ({ name = Root; children = ("Home","HelloWorld"); }, | ||
| 359 | |||
| 360 | { name = "HelloWorld"; action = "HelloWorld"; }, | ||
| 361 | |||
| 362 | { name = "Home"; action = "session.navController.homeAction"; }) | ||
| 363 | |||
| 364 | {{/code}} | ||
| 365 | |||
| 366 | If you just do that, the result will be something like this if you click on the HelloWorld tab of your application: | ||
| 367 | |||
| 368 | | **Reason:** | <er.extensions.appserver.navigation.ERXNavigationMenuItem name: er.extensions.appserver.navigation.ERXNavigationMenuItem subcomponents: null > valueForKey(): lookup of unknown key: 'HelloWorld'. The WOComponent er.extensions.appserver.navigation.ERXNavigationMenuItem does not have an instance variable of the name HelloWorld or HelloWorld, nor a method of the name HelloWorld, HelloWorld, getHelloWorld, or getHelloWorld | ||
| 369 | |||
| 370 | The reason is that you should have some subcomponent in navigation.ERXNavigationMenuItem, which in our case runs MainNavigationController. So we have to add an action to MainNavigationController: | ||
| 371 | |||
| 372 | {{color value="#8f1069"}}public{{/color}} ERXComponent helloWorld() { | ||
| 373 | |||
| 374 | ERXComponent nextPage = {{color value="#8f1069"}}null{{/color}}; | ||
| 375 | |||
| 376 | nextPage = (HelloWorld) myApp().pageWithName(HelloWorld.{{color value="#8f1069"}}class{{/color}}.getName(),session().context()); | ||
| 377 | |||
| 378 | {{color value="#8f1069"}}return{{/color}} nextPage; | ||
| 379 | |||
| 380 | } | ||
| 381 | |||
| 382 | We still are getting errors: | ||
| 383 | |||
| 384 | | **Reason:** | <er.extensions.appserver.navigation.ERXNavigationMenuItem name: er.extensions.appserver.navigation.ERXNavigationMenuItem subcomponents: null > valueForKey(): lookup of unknown key: 'HelloWorld'. The WOComponent er.extensions.appserver.navigation.ERXNavigationMenuItem does not have an instance variable of the name HelloWorld or HelloWorld, nor a method of the name HelloWorld, HelloWorld, getHelloWorld, or getHelloWorld | ||
| 385 | |||
| 386 | Perhaps add the session stuff to the NavigationList, so we change the navigation list item of HelloWorld to: | ||
| 387 | |||
| 388 | {{code}} | ||
| 389 | |||
| 390 | { | ||
| 391 | name = "HelloWorld"; | ||
| 392 | action = "session.navController.helloWorld"; | ||
| 393 | }, | ||
| 394 | |||
| 395 | {{/code}} | ||
| 396 | |||
| 397 | And indeed, we do get a response, but not what we expected: | ||
| 398 | |||
| 399 | [[image:NoMenu.png||border="1"]] | ||
| 400 | Where is the menu? Ahh, we forgot the PageWrapper to wrap the page: | ||
| 401 | |||
| 402 | ~==================================== | ||
| 403 | |||
| 404 | {{color value="#569191"}} | ||
| 405 | < | ||
| 406 | {{/color}} | ||
| 407 | |||
| 408 | {{color value="#115454"}}wo:PageWrapper{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 409 | |||
| 410 | {{color value="#569191"}} | ||
| 411 | < | ||
| 412 | {{/color}} | ||
| 413 | |||
| 414 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 415 | |||
| 416 | What is your name?{{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOTextField{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[username]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 417 | |||
| 418 | {{color value="#569191"}} | ||
| 419 | < | ||
| 420 | {{/color}} | ||
| 421 | |||
| 422 | {{color value="#115454"}}wo:WOSubmitButton{{/color}} {{color value="#901291"}}action{{/color}}{{color value="#569191"}}={{/color}}{{color value="#c07212"}}"[fixUserName]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 423 | |||
| 424 | {{color value="#569191"}} | ||
| 425 | </ | ||
| 426 | {{/color}} | ||
| 427 | |||
| 428 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 429 | |||
| 430 | {{color value="#569191"}} | ||
| 431 | < | ||
| 432 | {{/color}} | ||
| 433 | |||
| 434 | {{color value="#115454"}}wo:WOConditional{{/color}} {{color value="#901291"}}condition{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[userNameExtended]"{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 435 | |||
| 436 | {{color value="#000000"}} | ||
| 437 | Hello | ||
| 438 | {{/color}} | ||
| 439 | |||
| 440 | {{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOString{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[userNameExtended]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 441 | |||
| 442 | {{color value="#569191"}} | ||
| 443 | </ | ||
| 444 | {{/color}} | ||
| 445 | |||
| 446 | {{color value="#115454"}}wo:WOConditional{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 447 | |||
| 448 | {{color value="#569191"}} | ||
| 449 | </ | ||
| 450 | {{/color}} | ||
| 451 | |||
| 452 | {{color value="#115454"}}wo:PageWrapper{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 453 | ~==================================== | ||
| 454 | |||
| 455 | This should create all the menu's etc. Unfortunately, running this will result in the error: | ||
| 456 | \\ | ||
| 457 | |||
| 458 | {{noformat}} | ||
| 459 | |||
| 460 | NullPointerException | ||
| 461 | Â at PageWrapper.bodyClass(PageWrapper.java:25) | ||
| 462 | Â ... skipped 43 stack elements | ||
| 463 | |||
| 464 | {{/noformat}} | ||
| 465 | |||
| 466 | The reason is that PageWrapper needs the component that is wrapped to have a D2WContext. ERXComponent does not have a D2WContext. So we change the HelloWorld class to ERD2WPage: | ||
| 467 | |||
| 468 | {{color value="#8f1069"}} | ||
| 469 | public | ||
| 470 | {{/color}} | ||
| 471 | |||
| 472 | {{color value="#8f1069"}}class{{/color}} __HelloWorld__ {{color value="#8f1069"}}extends{{/color}} ERD2WPage { | ||
| 473 | |||
| 474 | That, unfortunately results in this error: | ||
| 475 | |||
| 476 | Apr 19 17:20:52 PSTennisExtended54682 WARN NSLog - <com.webobjects.appserver.//private.WOComponentRequestHandler>: Exception occurred while handling request~:// | ||
| 477 | |||
| 478 | {{color value="#180492"}} | ||
| 479 | {+}java.lang.NullPointerException{+} | ||
| 480 | {{/color}} | ||
| 481 | |||
| 482 | 2011-4-19 17:20:52 CEST <WorkerThread4> {{color value="#180492"}}{+}java.lang.NullPointerException{+}{{/color}} | ||
| 483 | |||
| 484 | at er.directtoweb.pages.ERD2WPage.appendToResponse({{color value="#180492"}}{+}ERD2WPage.java:644{+}{{/color}}) | ||
| 485 | |||
| 486 | The reason being, that a page should be constructed via D2WFactory, instead of myApp().pageWithName. Looking at the code, you will find that line 644 tries to get something out of d2wcontext, which only gets created via the D2WFactory: | ||
| 487 | |||
| 488 | {{code}} | ||
| 489 | |||
| 490 | Â Â Â String info = "(" + d2wContext().dynamicPage() + ")"; | ||
| 491 | |||
| 492 | {{/code}} | ||
| 493 | |||
| 494 | But the D2wFactory creates pages via rules, if you do not add a couple of rules you will get this error: | ||
| 495 | |||
| 496 | | **Error:** | java.lang.IllegalStateException: Couldn't find the dynamic page named HelloWorld in your DirectToWeb model.task and entity is null, it seems that one model, maybe ERDirectToWeb d2w.d2wmodel is not loaded | ||
| 497 | |||
| 498 | The reason that you get this error is because every DirectToWebpage should have an entity, and a task. And you have to make sure that the templateNameFortaskPage for that task points to your component: | ||
| 499 | |||
| 500 | pageConfiguration = 'HelloWorld' => entity = "Contacten" com.webobjects.directtoweb.EntityAssignment | ||
| 501 | |||
| 502 | pageConfiguration = 'HelloWorld' => task = "inspect" com.webobjects.directtoweb.Assignment | ||
| 503 | |||
| 504 | pageConfiguration = 'HelloWorld' => templateNameForInspectPage = "HelloWorld" com.webobjects.directtoweb.Assignment | ||
| 505 | |||
| 506 | 100 | ||
| 507 | |||
| 508 | ~: pageConfiguration = 'HelloWorld' => task = "inspect" com.webobjects.directtoweb.Assignment | ||
| 509 | 100 : pageConfiguration = 'HelloWorld' => templateNameForInspectPage = "HelloWorld" com.webobjects.directtoweb.Assignment | ||
| 510 | [[image:HelloWorldWrongTab.png||border="1"]] | ||
| 511 | We are nearly there.We just have to fix the navigationstate of the tab menu, which we can do via the rule: | ||
| 512 | |||
| 513 | pageConfiguration = 'HelloWorld' => navigationState = "HelloWorld" com.webobjects.directtoweb.Assignment [[image:HelloWorldRightTab.png||border="1"]] | ||
| 514 | And a submit will lead to: | ||
| 515 | |||
| 516 | [[image:InternalError.png||border="1"]] | ||
| 517 | |||
| 518 | The reason is that all the responses in the component should also be created as a D2WPage. Our action fixUsername() created a WOComponent but not in the D2WFactory. | ||
| 519 | |||
| 520 | We fix that by replacing | ||
| 521 | |||
| 522 | HelloWorld aPage = (HelloWorld) pageWithName({{color value="#4a0ffe"}}"HelloWorld"{{/color}}); | ||
| 523 | |||
| 524 | with: | ||
| 525 | HelloWorld aPage = (HelloWorld) D2W.factory().pageForConfigurationNamed({{color value="#4a0ffe"}}"HelloWorld"{{/color}}, session()); | ||
| 526 | |||
| 527 | And there we go: [[image:HelloWorldCorrect.png||border="1"]] | ||
| 528 | So resume: | ||
| 529 | |||
| 530 | ===== HelloWorld.java: ===== | ||
| 531 | |||
| 532 | {{color value="#8f1069"}} | ||
| 533 | import | ||
| 534 | {{/color}} | ||
| 535 | |||
| 536 | com.webobjects.appserver.WOContext; | ||
| 537 | |||
| 538 | {{color value="#8f1069"}} | ||
| 539 | import | ||
| 540 | {{/color}} | ||
| 541 | |||
| 542 | com.webobjects.directtoweb.D2W; | ||
| 543 | |||
| 544 | {{color value="#8f1069"}} | ||
| 545 | import | ||
| 546 | {{/color}} | ||
| 547 | |||
| 548 | er.directtoweb.pages.ERD2WPage; | ||
| 549 | |||
| 550 | {{color value="#8f1069"}} | ||
| 551 | public | ||
| 552 | {{/color}} | ||
| 553 | |||
| 554 | {{color value="#8f1069"}}class{{/color}} __HelloWorld__ {{color value="#8f1069"}}extends{{/color}} ERD2WPage { | ||
| 555 | |||
| 556 | {{color value="#8f1069"}}private{{/color}} String {{color value="#2608ca"}}username{{/color}}; | ||
| 557 | |||
| 558 | {{color value="#8f1069"}} | ||
| 559 | private | ||
| 560 | {{/color}} | ||
| 561 | |||
| 562 | {{color value="#000000"}}String{{/color}} {{color value="#2608ca"}}userNameExtended{{/color}}{{color value="#000000"}};{{/color}} | ||
| 563 | |||
| 564 | {{color value="#8f1069"}} | ||
| 565 | public | ||
| 566 | {{/color}} | ||
| 567 | |||
| 568 | HelloWorld(WOContext context) { | ||
| 569 | |||
| 570 | {{color value="#8f1069"}}super{{/color}}(context); | ||
| 571 | |||
| 572 | } | ||
| 573 | |||
| 574 | {{color value="#8f1069"}} | ||
| 575 | public | ||
| 576 | {{/color}} | ||
| 577 | |||
| 578 | ERD2WPage fixUserName() { | ||
| 579 | |||
| 580 | {{color value="#549172"}} | ||
| 581 | //create a new component, which will be sent to the user with it's name appended | ||
| 582 | {{/color}} | ||
| 583 | |||
| 584 | HelloWorld aPage = (HelloWorld) D2W.factory().pageForConfigurationNamed({{color value="#4a0ffe"}}"HelloWorld"{{/color}}, session()); | ||
| 585 | |||
| 586 | {{color value="#549172"}} | ||
| 587 | // we do not like WOBers without the name | ||
| 588 | {{/color}} | ||
| 589 | |||
| 590 | {{color value="#549172"}}{+}David{+}{{/color}} | ||
| 591 | |||
| 592 | String extendedUserName={{color value="#4a0ffe"}}""{{/color}}; | ||
| 593 | |||
| 594 | {{color value="#8f1069"}}if{{/color}}(username()={{color value="#8f1069"}}null{{/color}}){ | ||
| 595 | |||
| 596 | {{color value="#000000"}} | ||
| 597 | | ||
| 598 | {{/color}} | ||
| 599 | |||
| 600 | {{color value="#000000"}}extendedUserName={{/color}}{{color value="#4a0ffe"}}"David-"{{/color}}{{color value="#000000"}}+username()+{{/color}}{{color value="#4a0ffe"}}"(There is no WOBber that doesn't have David in his firstname)"{{/color}}{{color value="#000000"}};{{/color}} | ||
| 601 | |||
| 602 | } {{color value="#8f1069"}}else{{/color}} { | ||
| 603 | |||
| 604 | extendedUserName={{color value="#4a0ffe"}}"Please fill in some name"{{/color}}; | ||
| 605 | |||
| 606 | } | ||
| 607 | |||
| 608 | {{color value="#000000"}} | ||
| 609 | | ||
| 610 | {{/color}} | ||
| 611 | |||
| 612 | {{color value="#549172"}}//set the User Name on the new page{{/color}} | ||
| 613 | |||
| 614 | aPage.setUserNameExtended(extendedUserName); | ||
| 615 | |||
| 616 | {{color value="#8f1069"}} | ||
| 617 | return | ||
| 618 | {{/color}} | ||
| 619 | |||
| 620 | aPage; | ||
| 621 | |||
| 622 | } | ||
| 623 | |||
| 624 | {{color value="#8f1069"}} | ||
| 625 | public | ||
| 626 | {{/color}} | ||
| 627 | |||
| 628 | String username() { | ||
| 629 | |||
| 630 | {{color value="#8f1069"}} | ||
| 631 | return | ||
| 632 | {{/color}} | ||
| 633 | |||
| 634 | {{color value="#2608ca"}}username{{/color}}{{color value="#000000"}};{{/color}} | ||
| 635 | |||
| 636 | } | ||
| 637 | |||
| 638 | {{color value="#8f1069"}} | ||
| 639 | public | ||
| 640 | {{/color}} | ||
| 641 | |||
| 642 | {{color value="#8f1069"}}void{{/color}} setUsername(String username) { | ||
| 643 | |||
| 644 | {{color value="#8f1069"}} | ||
| 645 | this | ||
| 646 | {{/color}} | ||
| 647 | |||
| 648 | .{{color value="#2608ca"}}username{{/color}} = username; | ||
| 649 | |||
| 650 | } | ||
| 651 | |||
| 652 | {{color value="#8f1069"}} | ||
| 653 | public | ||
| 654 | {{/color}} | ||
| 655 | |||
| 656 | String userNameExtended() { | ||
| 657 | |||
| 658 | {{color value="#8f1069"}} | ||
| 659 | return | ||
| 660 | {{/color}} | ||
| 661 | |||
| 662 | {{color value="#2608ca"}}userNameExtended{{/color}}{{color value="#000000"}};{{/color}} | ||
| 663 | |||
| 664 | } | ||
| 665 | |||
| 666 | {{color value="#8f1069"}} | ||
| 667 | public | ||
| 668 | {{/color}} | ||
| 669 | |||
| 670 | {{color value="#8f1069"}}void{{/color}} setUserNameExtended(String userNameExtended) { | ||
| 671 | |||
| 672 | {{color value="#8f1069"}} | ||
| 673 | this | ||
| 674 | {{/color}} | ||
| 675 | |||
| 676 | .{{color value="#2608ca"}}userNameExtended{{/color}} = userNameExtended; | ||
| 677 | |||
| 678 | } | ||
| 679 | |||
| 680 | | ||
| 681 | |||
| 682 | ===== HelloWorld.wo: ===== | ||
| 683 | |||
| 684 | {{color value="#569191"}} | ||
| 685 | < | ||
| 686 | {{/color}} | ||
| 687 | |||
| 688 | {{color value="#115454"}}wo:PageWrapper{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 689 | |||
| 690 | {{color value="#569191"}} | ||
| 691 | < | ||
| 692 | {{/color}} | ||
| 693 | |||
| 694 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 695 | |||
| 696 | What is your name?{{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOTextField{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[username]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 697 | |||
| 698 | {{color value="#569191"}} | ||
| 699 | < | ||
| 700 | {{/color}} | ||
| 701 | |||
| 702 | {{color value="#115454"}}wo:WOSubmitButton{{/color}} {{color value="#901291"}}action{{/color}}{{color value="#569191"}}={{/color}}{{color value="#c07212"}}"[fixUserName]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 703 | |||
| 704 | {{color value="#569191"}} | ||
| 705 | </ | ||
| 706 | {{/color}} | ||
| 707 | |||
| 708 | {{color value="#115454"}}wo:WOForm{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 709 | |||
| 710 | {{color value="#569191"}} | ||
| 711 | < | ||
| 712 | {{/color}} | ||
| 713 | |||
| 714 | {{color value="#115454"}}wo:WOConditional{{/color}} {{color value="#901291"}}condition{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[userNameExtended]"{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 715 | |||
| 716 | {{color value="#000000"}} | ||
| 717 | Hello | ||
| 718 | {{/color}} | ||
| 719 | |||
| 720 | {{color value="#569191"}}<{{/color}}{{color value="#115454"}}wo:WOString{{/color}} {{color value="#901291"}}value{{/color}} {{color value="#569191"}}={{/color}} {{color value="#c07212"}}"[userNameExtended]"{{/color}}{{color value="#569191"}}/>{{/color}} | ||
| 721 | |||
| 722 | {{color value="#569191"}} | ||
| 723 | </ | ||
| 724 | {{/color}} | ||
| 725 | |||
| 726 | {{color value="#115454"}}wo:WOConditional{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 727 | |||
| 728 | {{color value="#569191"}} | ||
| 729 | </ | ||
| 730 | {{/color}} | ||
| 731 | |||
| 732 | {{color value="#115454"}}wo:PageWrapper{{/color}}{{color value="#569191"}}>{{/color}} | ||
| 733 | |||
| 734 | ===== extra rules in user.d2wmodel: ===== | ||
| 735 | |||
| 736 | {{color value="#333333"}} | ||
| 737 | pageConfiguration = 'HelloWorld' => entity = "Contacten" \[com.webobjects.directtoweb.EntityAssignment\] | ||
| 738 | {{/color}} | ||
| 739 | |||
| 740 | {{color value="#333333"}} | ||
| 741 | pageConfiguration = 'HelloWorld' => task = "inspect" \[com.webobjects.directtoweb.Assignment\] | ||
| 742 | {{/color}} | ||
| 743 | |||
| 744 | {{color value="#333333"}} | ||
| 745 | pageConfiguration = 'HelloWorld' => templateNameForInspectPage = "HelloWorld" \[com.webobjects.directtoweb.Assignment\] | ||
| 746 | {{/color}} | ||
| 747 | |||
| 748 | {{color value="#333333"}} | ||
| 749 | pageConfiguration = 'HelloWorld' => navigationState = "HelloWorld" \[com.webobjects.directtoweb.Assignment\] | ||
| 750 | {{/color}} | ||
| 751 | |||
| 752 | ===== Extra item in NavigationMenu.plist: ===== | ||
| 753 | |||
| 754 | { | ||
| 755 | |||
| 756 | name = "HelloWorld"; | ||
| 757 | |||
| 758 | action = "session.navController.helloWorld"; | ||
| 759 | |||
| 760 | } | ||
| 761 | |||
| 762 | ===== Extra WOComponent method in MainNavigationController: ===== | ||
| 763 | |||
| 764 | {{color value="#8f1069"}}public{{/color}} WOComponent helloWorld() { | ||
| 765 | |||
| 766 | WOComponent nextPage = {{color value="#8f1069"}}null{{/color}}; | ||
| 767 | |||
| 768 | nextPage = D2W.factory().pageForConfigurationNamed({{color value="#4a0ffe"}}"HelloWorld"{{/color}}, session()); | ||
| 769 | |||
| 770 | {{color value="#8f1069"}}return{{/color}} nextPage; | ||
| 771 | |||
| 772 | } | ||
| 773 | |||
| 774 | {{color value="#000000"}} | ||
| 775 | {*}ERExcelLook specific rules{*} | ||
| 776 | {{/color}} | ||
| 777 | |||
| 778 | [[Additional tips for ERExcelLook]] |