Wiki source code of Modern Binding Styles

Last modified by Kieran Kelleher on 2008/01/16 16:56

Show last authors
1 The WOComponent Editor in WOLips adds support for extensions to the bindings and different binding styles than what WebObjects Builder supported. It is important to note the difference between development time and run time. At development time, bindings are restricted by the editor (WebObjects Builder or WOComponent Editor). At runtime, bindings are evaluated by the WebObjects parser. The parser is much more flexible than what WebObjects Builder generated and it can also be replaced (as Project Wonder does).
2
3 == Extensions to Standard Bindings ==
4
5 These formats are support by the WOComponent Editor and the WebObjects run-time parser but not by WebObjects Builder?
6
7 All in one tag:
8
9 {{code}}
10
11 <webobject name="FirstName"/>
12
13 {{/code}}
14
15 Name on closing tag (useful for conditionals and repetitions that wrap a lot of content:
16
17 {{code}}
18
19 <webobject name="EmployeeRepetition">
20 ...
21 ...
22 ...
23 </webobject name="EmployeeRepetition">
24
25 {{/code}}
26
27 This style can make larger pages much easier to maintain.
28
29 == WOOGNL / Inline Bindings ==
30
31 These formats are only supported by the WOComponent Editor and the Wonder run-time parser. You need to be using Project Wonder to be using these.
32
33 Inline bindings allow you to embed wod attributes into your html template. For instance:
34
35 {{code}}
36
37 <wo:WOConditional condition = "$inEditMode">Editing Now</wo:WOConditional>
38
39 {{/code}}
40
41 or the "tag shortcut" style:
42
43 {{code}}
44
45 <wo:if condition = "$inEditMode">Editing Now</wo:if>
46
47 {{/code}}
48
49 This can often actually make templates easier to follow when used wisely. When bindings extend beyond two or three, it can often get confusing. One of the nice features of Wonder's inline binding implementation is that you can mix and match in a single template where it makes sense.
50
51 Another very useful feature of inline bindings is that you can represent a template with a single String value, which makes it easier to provide features like dynamic templates that load out of a database (see ERXInlineTemplate in Project Wonder).
52
53 For more extensive details on inline bindings (and helper functions, which come along with it), read the following wotips post:
54
55 * [[http:~~/~~/groups.google.com/group/wotips/browse_thread/thread/d89adb4015442ef0/be5d84d798bec5a2#be5d84d798bec5a2>>url:http://groups.google.com/group/wotips/browse_thread/thread/d89adb4015442ef0/be5d84d798bec5a2#be5d84d798bec5a2||shape="rect"]]
56 * [[http:~~/~~/groups.google.com/group/wotips/browse_thread/thread/466ef5224633521e/bce1de1aaf845c9b#bce1de1aaf845c9b>>url:http://groups.google.com/group/wotips/browse_thread/thread/466ef5224633521e/bce1de1aaf845c9b#bce1de1aaf845c9b||shape="rect"]]
57
58 {{note title="~"How Do I Specify Constants?~""}}
59 Precede any inline binding whether keypath or constant with $ symbol. So the constant true would be condition="$true" and the constant 345 would be written like value="$345"
60 {{/note}}
61
62 === Activating Inline Bindings ===
63
64 Add these to the {{code language="none"}}Properties{{/code}} file in your application:
65
66 {{code}}
67
68 ognl.active = true
69 ognl.helperFunctions=true
70 ognl.inlineBindings=true
71
72 {{/code}}
73
74 If you want to be able to use this with the standard HTML tags (e.g. {{code language="none"}}<img src="$dynamicPath" />{{/code}} you have to add this as well:
75
76 {{code}}
77
78 ognl.parseStandardTags=true
79
80 {{/code}}
81
82 === Handy Tips ===
83
84 **Tip 1**: Use {{code language="none"}}<wo:not condition = "$isEditable">{{/code}} instead of a negated if. wo:not is implemented as a TagProcessor in wonder that turns into (WOConditional, negate = true, condition = whatever).
85
86 **Tip 2**: while {{code language="none"}}<wo:whatever>{{/code}} is implemented in the validator as a "loose" namespace (that is, {{code language="none"}}<wo:if>{{/code}} can be closed by {{code language="none"}}</wo>{{/code}}), you get better error checking if you close your {{code language="none"}}<wo:whatever>{{/code}} with {{code language="none"}}</wo:whatever>{{/code}}. Basically a {{code language="none"}}</wo>{{/code}} can close any {{code language="none"}}<wo:whatever>{{/code}}, but a {{code language="none"}}</wo:somethingElse>{{/code}} can't. So if you have {{code language="none"}}<wo:if></wo:not>{{/code}} that would be an error, but {{code language="none"}}<wo:if></wo>{{/code}} would not, so you potentially miss a family of mistakes.
87
88 **Tip 3**: It is possible to write: {{code language="none"}}<img src="$imagePath" />{{/code}} now. With {{code language="none"}}ognl.parseStandardTags=true{{/code}}, the parser will convert that to a WOGenericContainer and pull the imagePath dynamically.
89
90 === Short Names in Inline Bindings ===
91
92 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOString", "string");
93 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOString", "str");
94 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("ERXElse", "else");
95 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOConditional", "if");
96 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOConditional", "condition");
97 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOConditional", "conditional");
98 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOHyperlink", "link");
99 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WORepetition", "loop");
100 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOTextField", "textfield");
101 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOCheckBox", "checkbox");
102 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOHiddenField", "hidden");
103 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOPopUpButton", "select");
104 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WORadioButton", "radio");
105 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOPasswordField", "password");
106 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOFileUpload", "upload");
107 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOText", "text");
108 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOForm", "form");
109 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("WOSubmitButton", "submit");
110 WOHelperFunctionHTMLTemplateParser.registerTagShortcut("ERXLocalizedString", "localized");
111 WOHelperFunctionHTMLTemplateParser.registerTagProcessorForElementType(new NotTagProcessor(), "not");
112
113 === Mike Schrag's Inline Binding Shortcuts ===
114
115 [[image:attach:WonderShortCuts.png]]