Changes for page Development-General Best Practices
Last modified by Pascal Robert on 2013/08/20 19:43
From version 2.1
edited by smmccraw
on 2007/07/08 09:45
on 2007/07/08 09:45
Change comment:
There is no comment for this version
To version 3.1
edited by Pascal Robert
on 2007/09/03 13:44
on 2007/09/03 13:44
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. smmccraw1 +XWiki.probert - Content
-
... ... @@ -16,83 +16,83 @@ 16 16 17 17 If you have WORepetitions, confirm that none of your code changes the sizes of those arrays or indexes on which their sizes depend between your activation of super.appendToResponse and the completion of the corresponding invokeAction for that page. 18 18 19 -For a deeper explanation of this process and its ramifications, see [[In particular, read the last paragraph, and the following page ~[http: ~~/~~/developer.apple.com/documentation/LegacyTechnologies/WebObjects/WebObjects_4.5/System/Documentation/Developer/WebObjects/DevGuide/WOClasses21.html>>http://developer.apple.com/documentation/LegacyTechnologies/WebObjects/WebObjects_4.5/System/Documentation/Developer/WebObjects/DevGuide/WOClasses20.html]].]. In this latter page, pay close attention to the second to last paragraph.19 +For a deeper explanation of this process and its ramifications, see [[In particular, read the last paragraph, and the following page ~[DevGuide-WOClasses>>http://developer.apple.com/documentation/LegacyTechnologies/WebObjects/WebObjects_4.5/System/Documentation/Developer/WebObjects/DevGuide/WOClasses21.html||title="http://developer.apple.com/documentation/LegacyTechnologies/WebObjects/WebObjects_4.5/System/Documentation/Developer/WebObjects/DevGuide/WOClasses20.html"]].]. In this latter page, pay close attention to the second to last paragraph. 20 20 21 21 == Creating WOComponents == 22 22 23 23 Rather than use 24 24 25 -{{ panel}}25 +{{code}} 26 26 27 - 27 +MyNewPage nextPage = (MyNewPage)pageWithName("MyNewPage"); 28 28 29 -{{/ panel}}29 +{{/code}} 30 30 31 31 Prefer this form: 32 32 33 -{{ panel}}33 +{{code}} 34 34 35 - 35 +MyNewPage nextPage = (MyNewPage)pageWithName(MyNewPage.class.getName()); 36 36 37 -{{/ panel}}37 +{{/code}} 38 38 39 39 The class.getName() allows Eclipse to do proper refactoring and you can right click=>References=>Workspace your class and truly find all the references vs just having a string references. One other advantage that it has is that if you have two pages with the same name but in different packages, this avoids confusion. If you just use pageWithName("MyNewPage";), WO can return the wrong one. Minor change but really nice benefits. 40 40 41 41 If you use 1.5, you can use the 1.5 variation: 42 42 43 -{{ panel}}43 +{{code}} 44 44 45 - 46 - 47 - 48 - 45 +@SuppressWarnings("unchecked") 46 +public <T extends WOComponent> T pageWithName(Class<T> componentClass) { 47 + return (T) super.pageWithName(componentClass.getName()); 48 +} 49 49 50 -{{/ panel}}50 +{{/code}} 51 51 52 52 which removes a cast: 53 53 54 -{{ panel}}54 +{{code}} 55 55 56 - 56 +MyNewPage nextPage = pageWithName(MyNewPage.class); 57 57 58 -{{/ panel}}58 +{{/code}} 59 59 60 60 == Avoid String Literals == 61 61 62 62 KeyValueCoding (aka KVC) tends to encourage the use of constructs like this 63 63 64 -{{ panel}}64 +{{code}} 65 65 66 - 66 +website.addObjectToBothSidesOfRelationshipWithKey(newFolder, "folders"); 67 67 68 -{{/ panel}}68 +{{/code}} 69 69 70 70 This litters code with hard coded strings. Changing the property name breaks code with no compilation warnings. If you use EOGenerator to generate constants for the names: 71 71 72 -{{ panel}}72 +{{code}} 73 73 74 - 74 +public static final String FOLDERS = "folders"; 75 75 76 -{{/ panel}}76 +{{/code}} 77 77 78 78 You can use them in place of the hard coded strings and get errors when changes affect code: 79 79 80 -{{ panel}}80 +{{code}} 81 81 82 - 82 +website.addObjectToBothSidesOfRelationshipWithKey(newFolder, FOLDERS); 83 83 84 -{{/ panel}}84 +{{/code}} 85 85 86 86 An EOGenerator template (fragement) to do this: 87 87 88 -{{ panel}}88 +{{code}} 89 89 90 - 90 +public static final String ENTITY_NAME = "<$name$>"; 91 91 92 - 93 - 92 +<$foreach propertyName classPropertyNames.@reversedArray do$> 93 + public static final String <$propertyName.uppercaseString$> = "<$propertyName$>";<$endforeach do$> 94 94 95 -{{/ panel}}95 +{{/code}} 96 96 97 97 === Except === 98 98 ... ... @@ -99,6 +99,6 @@ 99 99 * This does not address the related issue when property names are used in bindings in a wod file 100 100 * This does not work in the (admittedly rare) case where one class implements multiple entities. EOGenerator assumes one entity == one class. So, MyEO.ENTITY//NAME will return the name of the last entity to get generated. // 101 101 102 -See the [[EOGenerator>> Programming__WebObjects-EOF-Using EOF-EOGenerator]] page for more similar tricks.102 +See the [[EOGenerator>>EOF-Using EOF-EOGenerator]] page for more similar tricks. 103 103 104 104 Category:WebObjects