Changes for page Hello World - Your First WebObjects Application
Last modified by Denis Frolov on 2012/01/21 22:03
From version 13.1
edited by smmccraw
on 2007/07/08 09:44
on 2007/07/08 09:44
Change comment:
There is no comment for this version
To version 16.1
edited by Paul Hoadley
on 2011/05/06 09:57
on 2011/05/06 09:57
Change comment:
Removed link to non-existent resource. Added notice about legacy content.
Summary
-
Page properties (3 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 - Programming__WebObjects-Hands On___Hello World - Your First WebObjects Application1 +Hello World - Your First WebObjects Application - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. smmccraw1 +XWiki.paulh - Content
-
... ... @@ -1,8 +1,13 @@ 1 - === Createa New WebObjectsProject===1 +{{note title="Legacy Documentation"}} 2 2 3 -Launch Xcode (found in Developer->Applications). Choose 'New Project...' from the 'File' menu to display to 'New Project' Assistant. 4 -Scroll to the bottom of the list of project types and choose 'WebObjects Application'. 3 +Apart from a brief mention of WOLips in the first section, this document contains a tutorial aimed at legacy tools: Xcode and WO Builder. A better entry-level document is [Create a new WO Application|http://wiki.objectstyle.org/confluence/display/WOL/Create+a+new+WO+Application]. 5 5 5 +{{/note}} 6 + 7 +=== Create a New WebObjects Project === 8 + 9 +Make sure that Eclipse and WOLips are [[installed>>WOL:Install WOLips with Eclipse Update Manager]]. Launch Eclipse, chosse //New//>//WebObjects Application// from the //File// menu. 10 + 6 6 Click 'Next'. 7 7 Type 'HelloWorld' as the 'Project Name' and click on the 'Set...' button to specify that you'd like to save your project to the desktop, or where ever you'd like to save your project. Note that earlier versions of WebObjects had problems building projects if their path had any spaces. 8 8 ... ... @@ -9,7 +9,7 @@ 9 9 Click 'Next' lots more times until you come to a 'Finish' button, and click it (we'll cover all those other screens later). 10 10 If you did everything right, you'll end up with something that looks like this (depending on how you've configured Xcode). 11 11 12 -=== Edit the 'Main' Component 17 +=== Edit the 'Main' Component === 13 13 14 14 You should now be looking at a brand-new WebObjects project. This is your 'blank canvas' if you're fond of analogies. 15 15 It may seem a little complicated if you're used to creating web sites that consist only of HTML files and images, but it isn't too much more complicated. The main files we're interested in are in the 'Web Components' group. ... ... @@ -16,13 +16,13 @@ 16 16 17 17 When you first create a WebObjects project, you will have just one 'Component', the 'Main' one. 18 18 A WebObjects component consists of a folder and a bunch of files, but at this stage we're really only interested in 2: 19 - <ul>20 - <li>Main.wo - which contains the interface</li>21 - <li>Main.java - where we'll put the logic for the Main.wo page.</li>22 - </ul>24 + 25 +* Main.wo - which contains the interface 26 +* Main.java - where we'll put the logic for the Main.wo page. 27 + 23 23 Double-click on the 'Main.wo' file to edit the interface in WebObjects Builder. 24 24 25 - You should see something like the screen above. This is how a WebObjects component looks in WebObjects Builder. The top half of the window is a What-You-See-Is-What-You-Get (most of the time (WYSIWYG(MOTT)) HTML editor where you can design your pages. The bottom half of the window is used to connect interface elements to variables in the 'logic' section of your web application.30 +You should see something like the screen above. This is how a WebObjects component looks in WebObjects Builder. The top half of the window is a What-You-See-Is-What-You-Get (most of the time (WYSIWYG(MOTT)) HTML editor where you can design your pages. The bottom half of the window is used to connect interface elements to variables in the 'logic' section of your web application. 26 26 Add the text "Hello, what is your name?" by typing in the top half of the window. 27 27 28 28 Add some form elements to the page by selecting a 'WOForm', a 'Text Field' and a 'Submit Button' from the 'Forms' menu bar item. ... ... @@ -29,7 +29,7 @@ 29 29 Finally, add a place-holder String2 by selecting 'String' from the 'WebObject' menu bar item. 30 30 You now have a finished interface: a heading inviting visitors to your web application to enter their name, a text field where they can type their name, a button so they can submit the form and a place-holder for the string of characters that you want to display in response. 31 31 32 -=== Add an Action and a Key 37 +=== Add an Action and a Key === 33 33 34 34 Now that you have an interface, you need to write the logic of your first WebObjects application. This application allows a user to type their name in to a form and displays a message in response. In order to achieve this, we're going to write a little Java code. 35 35 Each WebObjects component has a Java file that contains the logic for the component. Java is an object-oriented programming language so if you're not familiar with object-oriented programming the next section might introduce some new concepts. At this stage you don't need to know the gory details of object-oriented programming, but it might help to understand some basic terminology. ... ... @@ -53,27 +53,21 @@ 53 53 {{code}} 54 54 55 55 public class Main extends WOComponent { 56 -{panel} 57 57 public String visitorsName; 58 58 public String message; 59 -{panel} 60 - 61 -{panel} 63 + 62 62 public Main(WOContext context) { 63 63 super(context); 64 64 } 65 -{panel} 66 66 67 67 public WOComponent sayHello() { 68 -{panel} 69 69 return null; 70 70 } 71 -{panel} 72 72 } 73 73 74 74 {{/code}} 75 75 76 -=== Connect the Interface to the Logic 75 +=== Connect the Interface to the Logic === 77 77 78 78 Now you've created the interface and added a variable and method to the underlying Java code, all that we need to do is 'hook-up' the interface to the logic. 79 79 We need to specify that the 'sayHello' method should happen when the button is clicked and that the value for the 'visitorsName' variable should come from the text field. To do this we need to switch back to WebObjects Builder. ... ... @@ -81,10 +81,9 @@ 81 81 Click and drag from the space next to 'visitorsName' in the bottom half of the window to the text field and choose 'value' from the drop-down menu to indicate that you want the 'visitorsName' variable to get its value from the text field. 82 82 Repeat this step to bind the 'value' of the dynamic String to the 'message' variable and the 'action' of the 'Submit' button to the 'sayHello' method in the underlying Java class. 83 83 84 - 85 85 Once you've hooked up the interface to the logic, the only thing left to do is write a line (or two) of Java code to compose a custom message in response to the click of the button. 86 86 87 -=== Edit the Java Code 85 +=== Edit the Java Code === 88 88 89 89 Open the 'Main.java' file by double-clicking on it. 90 90 Fill out the details of the sayHello method like the example below. Basically, when this method is executed we want to construct a custom message based on the variable 'visitorsName' which will contain the name of the person we want to greet. ... ... @@ -92,27 +92,19 @@ 92 92 {{code}} 93 93 94 94 public class Main extends WOComponent { 95 -{panel} 96 96 public String visitorsName; 97 97 public String message; 98 -{panel} 99 - 100 -{panel} 95 + 101 101 public Main(WOContext context) { 102 102 super(context); 103 103 } 104 -{panel} 105 105 106 106 public WOComponent sayHello() { 107 -{panel} 108 108 message = "Hi there, " + visitorsName + "!"; 109 109 return null; 110 110 } 111 -{panel} 112 112 } 113 113 114 114 {{/code}} 115 115 116 116 Congratulations - you've just written your first WebObjects application. Make sure you've saved both the Main.wo file in WebObjects Builder and the Main.java file in XCode and you're ready to compile your code and run the application. Click on the 'Build and Go' button in XCode to test your application. 117 - 118 -Category:WebObjects