An Introduction to WebObjects
Pages: 1, 2, 3
You will be using the pk Attribute as your Primary Key.
EOF will handle its generation for you; however, you will need to indicate
that it is to be used as a Primary Key. Therefore, click in the Key
column.
After you've modeled your Entities, you'll want to double check that
the External type (the type of data your database will store the information
as) and the Internal type (the type of Object EO will use) for each
Attribute. Some of this may seem tedious, especially when you start
building larger models, but the attention you pay to details here will
pay off tremendously in the future. Once you're happy with your Model,
you can have EOModeler create your database for you. Simply click on
the SQL button
and then Execute SQL. If all goes well, you'll have a your database.
I also need to mention that EOModeler can reverse-engineer a previously created database. So, if you just happen to get the call requesting to build a system on a current database, you'll be able to have EOModeler do the heavy lifting for you. WO has a great technology called Direct To Web (D2W) that can give you web-driven access to a database in minutes. At first glance D2W may look like a toy, but trust me -- it's not.
Store Variables in the Database
In order to move forward with this article, you need a way to get information into the database. There are a number of ways to accomplish this, but since this is a WO/EO article, I figured I'd detour just briefly.
In Project Builder, create a new File. The Assistant will present itself.
You should select the Display Group Component, located under the WebObjects
heading. You should then name your new component UserGroup.
After naming your component, you will be presented with the choice of
an Entity, which should be a simple choice, as you only have one.
The Assistant will then walk you through a number of questions. When choosing the Layout, you should select "Selected Record" and "Matching Records" for the configuration.
What you are actually doing is creating a simple page to Search, Edit, Create, and Delete information stored in the User table of the database. You will then be prompted through additional configuration options. When you have walked through the steps, click Finished.
Feel free to do this part of the article a few times, each time selecting different options. It should prove insightful.
Now you are going to add a hyperlink on your Main page and link it to
the new UserGroup page. This will allow you to add new
Users to the database. You would obviously only use this UserGroup
page as an administrator of your site, as it's not restricted in what
it can accomplish.
When you created the UserGroup page, a WODisplayGroup was
created and configured for you. WebObjects provides a class called WODisplayGroup,
which is used in the UserGroup page. You are going to use
a WODisplayGroup for your Main page, as well. My feelings on WODisplyGroup?
"There's gold in them thar hills."
There are three ways to get a WODisplayGroup into an already existing
page. You can add it by:
- Writing the code directly in the .java file.
- Adding a Key in WOBuilder.
- Dragging the Entity from EOModeler to WOBuilder.
I typically use method (2) or (3). For this article, you'll use option (3), since it's the most fun.
From the EOModel window, click and drag your User Entity
to the WOBuilder window for your Main page. You will be prompted to
"Add & Configure" the new DisplayGroup being created.
Name the DisplayGroup userDisplayGroup. The default configuration
will be fine.
You can now bind the username and password
WOTextFields in your Login panel to the userDisplayGroup.
For the username, you're going to traverse the hierarchy
in the Object Browser to userDisplayGroup>queryMatch>username.
You will do the same for the password.
Next, you should bind the Submit button. Connect it to the userDisplayGroup>qualifyDataSource
method. When a user clicks Submit, the WODisplayGroup will use the supplied
username/password to try to find a match in the database.
Next, add a WOHyperlink
to the page. Name it "Create" and bind it to the UserGroup
page. You can accomplish this by using the pop-up menu to the right
of the pageName key in the Inspector Panel.
On the Main.wo page, add a couple of WOConditional
elements. You'll notice they have a plus sign on them. Click on one
of the plus signs and change it to a minus sign. Inside of the WOConditional
with the plus, type "Please log in..." In the one with the
minus, type "Thank you, " and then add a WOString
.
Bind this WOString to userDisplayGroup>selectedObject>username.
Your completed Login panel should look similar to this:
Now that you've taken advantage of Apple's generosity, you can greatly reduce the amount of code you need to maintain. Your entire Main.java file can now look like this:
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class Main extends WOComponent {
public WODisplayGroup userDisplayGroup;
public Main(WOContext context) {
super(context);
}
}
Go ahead and "Build and Run" your application. Initially, you
won't have any data in your database. In order to insert some data,
you will use the "Create" hyperlink. The UserGroup
page will allow you to create a new user and save the information appropriately.
Since you are now connected to a database, the information is persistent. Try stopping your application and running it again. Try using the Login panel. The information you've entered for users should be the same as it was when you stopped.
Apple provides sample code with WebObjects for creating a Login Panel using the Basic Authentication protocol. It is up to you (or the boss man) to decide whether Basic Authentication protocol is acceptable for your project.
Parting Thought
As I mentioned earlier, the Apple Music Store is a WebObjects application. When you access the Apple Music Store, you'll notice that you can find out what music other people are buying, whether it's through the Top 10 list or the "...other people bought" suggestion. Of course, you can also do a simple search. Obviously, Apple isn't guessing at this information, so you can conclude they're keeping the information in a persistent store: a database. The WebObjects set of frameworks makes all of this possible.
Josh Paul is the founder and CEO of Aweli, a startup focused on digital video solutions, and the author of Digital Video Hacks. He has provided software and service solutions to entertainment production companies throughout Los Angeles and New York.
Return to the Mac DevCenter
-
Direct to Web java.lang.ClassNotFoundException: Application error
2004-12-30 12:42:33 Florijan [View]
-
Direct to Web java.lang.ClassNotFoundException: Application error
2004-12-30 14:17:43 Josh Paul |
[View]
- Trackback from http://tourniquet.on.silkblogs.com/SilkWare/WebObjects/SilkWare.woa/wpa/com.silkblogs.wo.delivery.Actions/on/tourniquet/1310/entry
Silkblogs on WebObjects: EOModeler (3 of 3)
2004-11-14 08:09:07 [View]
- Trackback from http://tourniquet.on.silkblogs.com/SilkWare/WebObjects/SilkWare.woa/wpa/com.silkblogs.wo.delivery.Actions/on/tourniquet/1310/entry
Silkblogs on WebObjects: EOModeler (3 of 3)
2004-11-14 08:06:01 [View]
- Trackback from http://tourniquet.on.silkblogs.com/SilkWare/WebObjects/SilkWare.woa/wpa/com.silkblogs.wo.delivery.Actions/on/tourniquet/1309/entry
Silkblogs on WebObjects: WOBuilder (2 of 3)
2004-11-12 19:47:17 [View]
- Trackback from http://www.semanticwave.com/blog/archives/000135.jsp
Creative Namespaces and Syntactic Sugar
2004-05-18 02:09:06 [View]
- Trackback from http://www.lehopictures.com/links/archives/002100.php
Trackback Message
2004-03-19 17:00:25 [View]
-
MySQL
2003-10-09 12:51:50 anonymous2 [View]
-
WebObjects Book(s), Please!
2003-10-07 09:20:16 anonymous2 [View]
-
Thanks!!!
2003-10-05 13:16:55 anonymous2 [View]
-
Please.. books! and support from Apple
2003-10-05 04:42:02 thajeztah [View]
-
Yes, but...
2003-10-01 23:23:40 anonymous2 [View]
-
We want more....
2003-09-30 11:02:45 anonymous2 [View]
-
More, please!
2003-09-29 00:17:51 cmittendorf [View]
-
WebObjects tutorial
2003-09-28 17:06:12 anonymous2 [View]
-
How about a book O'Reilly?
2003-09-27 16:33:57 anonymous2 [View]
-
http://www.codon4.com
2003-09-27 08:03:33 anonymous2 [View]
-
More WO stuff on MacDevCenter please.
2003-09-27 07:36:50 anonymous2 [View]
-
Open Source Alternative?
2003-09-27 07:16:37 anonymous2 [View]
-
Open Source Alternative?
2003-10-01 11:25:58 anonymous2 [View]
-
Open Source Alternative?
2003-09-28 20:46:39 anonymous2 [View]
-
Open Source Alternative?
2003-09-29 07:41:37 anonymous2 [View]
-
Yes, but...
2003-09-27 02:51:17 anonymous2 [View]
-
Yes, but...
2003-10-17 19:14:40 anonymous2 [View]

