Using WebObjects "Direct to Web" Technology
by Josh Paul11/04/2003
Welcome to another installment of "WebObjects, EnterpriseObjects and You." Last time, we introduced you to the incredible WebObjects and EnterpriseObjects technologies. In this article, we'll acquaint you with the wonderfully powerful "Direct to Web" (D2W) technology.
RBRAD
Many of you have heard of Rapid Application Development (RAD). D2W takes RAD and injects a shot of technology steroids to create RBRAD, or Rule-Based Rapid Application Development. Through the use of an EOModel file and a D2WModel file, you're going to create a full-blown web application in just a few simple steps. In fact, you won't even have to work directly with the D2WModel. Don't believe me? Well, read on...
In order to exploit D2W's advantages, you'll want to start off with an EOModel. Fortunately, in the last article, you created a simple EOModel for maintaining information about Users. So, I'll skip over creating the EOModel and jump directly into D2W. However, just in case you cannot find your project, your EOModel should look similar to this:
|
Open ProjectBuilder and create a new Project. Select the "Direct to Web Application" option. Next, name your project and continue to select the default setup by clicking the "Next" button until you come upon the "Choose EOModels" window. At this point you'll want to "Add" your EOModel.
After adding your EOModel file, you'll be asked to choose a "Look" for your project. I usually select the "Neutral" option, but you're free to select whichever option suits you. In fact, I recommend going back through the previous steps a few times and selecting a different Look each time.
You're done ... sort of. ProjectBuilder offers you the option to "Build and launch project now", which will literally build and launch a full-blown web application. You should keep the option selected and click the "Finish" button.
Voila!
|
When the application launches, it will display the Main.wo component in your web browser. Since there's no real logic behind the Main.wo component yet, you'll be able to log into your application by simply clicking on the "Login" button.
Once you've logged into your application, you'll discover you can easily
search, create, edit, and even delete information in your database. All
of the pages being created use a "Rule" file called
a d2wmodel. Simply by looking at the full-blown
web application before you, you catch a small glimpse of the
amazing RBRAD world.
Customization Using the Assistant
After wandering around your new web application, go ahead and "Logout"
of the application. You'll notice that on your Main.wo component there's
a small checkbox labeled "Assistant."
Go ahead and check it off and log into your application again
The Assistant
Since you've requested the "Assistant" you'll discover a new "Customize" button on the left side of the window. When you decide to customize your application, a Java applet will start. A small frame will then be displayed at the bottom of your web browser to inform you of the Assistant's status.
A new window will open and allow you to customize your D2WModel file. By using the Assistant, you'll be able to customize your application without having to muck around with the XML behind it. You can also customize your D2WModel file using the Rule Editor application, but we'll stick to the Assistant ... for now.
Initially, you'll be presented with a window explaining that your current
page does not support customization. The initial page is called a D2WQueryAllPage
and will literally allow you to query any table in your database. Since
this is a broad search page, customizing it would be cumbersome, therefore
we're not going to try.
The Query Page
In order to customize the application, we're going to need a customizable page to be displayed. Fortunately, most pages are customizable, so we'll start of with a "Query" page. You can get a "Query" page by clicking the "Search" button.
Your Assistant should now look similar to this:
|
You probably don't want to look up Users by their password's,
so why don't you hide that information from the page. In order to do
this, simply select the password attribute in the Assistant
and click the GreenArrow:Left
button and then click the "Save" button.
Your web page should automatically reload. Additionally, the password
field should no longer be available. Go ahead and "Search DB"
for a User using the username field. You can leave the
username field blank if you'd like to retrieve all Users
from your database.
The List Page
The next page you'll see, after searching the database, will be a D2WListPage.
This page should provide a list of Users, based on the criteria you
entered for the search. Based on the last article, I received the following
list for my search:
|
Within the "List" page you can:
- Sort the list:
- Ascending (
) - Descending (
) - Unsorted (
)
- Ascending (
- Edit a row:

- Delete a row:

Since you're searching for Users based on their username,
you probably want to list the username before the password.
In order to accomplish this goal, simply select the username
in the Assistant (which should have updated its information to reflect
the current page; neat!) and click on the GreenArrow:Up
button. You can then click the "Save" button in the Assistant.
When you're back to using your web browser, click on the various Sort
buttons to get a feel for how they work.
The Edit Page
What fun would a database-driven site be without new and changing information?
The only way to get new information, or changed information, onto the
site is to "Edit" it, right? So, go ahead and choose a User
to edit by clicking on the edit
button.
Ugh. Our User's password is displayed before the username.
Well, that's easy to remedy. Simply follow the same steps as before:
- Select
usernamein the Assistant - Click the GreenArrow:Up
button - Click the "Save" button
For fun, go ahead and change the username to something else
and click the "Save"
button. You'll be returned to the "List" page and your newly
entered information will be displayed.
The Delete Page
For kicks, try using the "Delete"
button. You should receive a "Confirm" page, asking you for
a confirmation of your intent to delete the User you've selected. I
won't have any input at this point...it's your data, so you get to choose
whether you want to keep it around.
A little D2W insight
Well, you've either removed a User from your database or spared them
until the next round of experiments (insert evil laugh). Either
way, why don't you go "Home"
for a little reflection on what you've learned? Your "Home"
page is the D2WQueryAll page. For now, we'll keep it that
way.
When you click on the "New"
button, you'll receive an "Edit" page. At first inspection
this may seem a little odd, but if you think about it, when you create
a new User aren't you just creating an empty row in the database and
editing it? Well, what do you know, those engineer's over at
Apple might be onto something after
all.
If you leave either (or both) the username or password
fields empty and try to save the information, you should get an error.
|
Hey! How did WebObjects know that Users who don't have username's
or password's shouldn't be saved to the database? The answer
is simple: your EOModel.
The EOModel
If you open your EOModel file and inspect the User Entity, you should
discover that the username and password attributes
do not allow for NULL values.
|
You can confirm this by looking under the Allow Null Value
column. If the column is empty, and it should be, when your application
attempts to save information to the database the wonderful EnterpriseObjects
framework does it's magic. Your EOModel will help to inform you (or
your clients) the current data does not conform to the model and therefore
cannot be saved.
Pages: 1, 2 |

