Using WebObjects "Direct to Web" Technology
Pages: 1, 2
The D2WModel
As I mentioned earlier, there is a D2WModel file helping your application
on it's way to completion. For now, go ahead and logout of your application
and Stop it in ProjectBuilder. While using ProjectBuilder, you can find
your D2WModel (actually, your user.d2wmodel) file under
the "Resources" group.
|
Being the hacker that you are, you're bound to open this file sooner or later. You might as well make it sooner.
When you open the user.d2wmodel file, the RuleEditor application
should launch. Here comes the fun...
Your user.d2wmodel is a collection of Rules.
Each Rule is made up of a few parts:
- A Left-Hand Side (LHS): a condition that must be met.
- A Right-Hand Side (RHS): a Key/Value pair to be used when the LHS is fulfilled.
- A Priority: a number indicating your preference for the RHS to be used. (I'll explain more in a minute.)
Rules in your user.d2wmodel file. I'm
going to help you dissect one of them:
|
The highlighted Rule can be read as follows:
If the current
task(i.e. action) is "Edit" and the currentEntity's (i.e. table) name is "User"
then
display theusernameandpasswordattributes (i.e. columns) on the current page.
In other words, when someone wants to "Edit" a User, give them
access to the username and password fields.
So, what about this whole Priority business? In order to
demonstrate it, go ahead and copy the highlighted Rule
then paste it. Then select the newly created Rule.
You should change the Right-Hand Side's Value from (username,
password) to (username).
|
You will also want to change the Rule's Priority
to a number higher than 100...like 101. You should then save your changes.
Back to ProjectBuilder
Next, "Launch" your application. As before, you can login without entering any credentials (you should really fix that...see the previous article). When you go to create a "New" User, you will receive the "Edit" page, just like before.
Only this time, something has changed. Sure enough, you can only enter
information for the User's username. This is going to cause
major problems, since you can't save a User without a password.
Go ahead, just try it!
You should leave your web browser open, since your going to be going back to it very shortly.
Open your user.d2wmodel again and change the priority of
semi-new Rule to a number less than 100...like 99. Save
your changes and go back to your web browser. Once you're back using
your web browser again, click on the "Cancel" ![]()
button. After receiving the "Home" page, try creating a new
User again. You should now be back to the original option of username
and password.
What has happened is D2W evaluated the Rules in your D2WModel.
When D2W came across two LHS entries that matched, D2W looked to the
Priority to determine which Rule to use. Not
only that, but it did so without requiring you to rebuild your application.
That's what I'd call Rapid.
Throw D2W an uppercut
So, tracking your Users username's and password's
isn't enough. I think you'll want to track a little more information,
maybe their First and Last names. If you open your EOModel file, you
can easily add this information...so you might as well.
Change the User Entity
To create the nameFirst and nameLast attributes,
I simply performed a copy and paste combination
using the username attribute. I then renamed both the Name
and Column information to reflect my new criteria. I also
decided to allow NULL values by checking the option under
the Allow Null Value column.
|
Since I've edited my EOModel, my database needs to contain a similar schema. EOModeler used to allow you to "Synchronize Schema..." fairly reliably (you can still find this command under the "Model" menu). However, with the change to JDBC, the success of a synchronization will depend on your database vendor (and its Plugin). In order to get in sync, you can either:
- Successfully perform a "Synchronize Schema..." command.
- Alter your database's tables by hand.
- Use EOModeler's SQL generation tool.
Being the daring person that I am, and the fact I'm using a test database,
I chose to simply use EOModeler's SQL generation. By clicking the SQL
button in EOModeler, you will be presented with a variety of options.
Based on my selections, when I click "Execute SQL", EOModeler
is going to drop the User table (and the data contained in it). If you
are not using a test database do not drop your table...but
you already know that...right?
|
Once you have your EOModel and database in sync, you can return back to ProjectBuilder.
Work with the Assistant
When you "Build and Launch" your application, login, and browse
around your site, you'll discover the changes you have made to the User
Entity are not available. This is because you previously created a set
of Rules and D2W isn't going to ignore them.
If you enable the Assistant (remember the checkbox on the Login page?)
and navigate to an "Edit" page, you'll discover the Assistant
lists the nameFirst and nameLast attributes
in the left most browser (aka the key path browser).
|
Follow your intuition and select the nameFirst attribute
and click on the GreenArrow:Right
button. You should then find the nameFirst listed below
the username and password attributes. When
you click on the "Save" button in the Assistant window, your
web browser should reload with your changes.
Moving Forward
From this point, you should have enough information to work with the
D2WAssistant, EOModeler and RuleEditor to create a simple application
for maintaining User information. Oh, and if you hadn't noticed, there's
no code here to maintain (well, okay, the user.d2wmodel
file is kind of code).
Hey! If you combine this article with the previous article, and sprinkle in a little ingenuity, you should be able to create a simple User account maintenance application. The bonus will be the fact you'll have very little code to maintain.
If you want to explore D2W further, I highly recommend Apple's documentation provided with WebObjects. I would also be remiss, if I did not mention the open source set of WebObjects frameworks and tools at Project WONDER. I must warn you, however, that WONDER is huge and not for the faint of heart.
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
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 6 of 6.
-
Another WebObjects article, WooHoo!
2003-11-09 21:26:50 anonymous2 [Reply | View]
Another WebObjects article! Hope these articles keep coming to cover more topics like D2J, Enterprise Objects, etc.
Good work. Keep it up.
-
WebObjects 6.0?
2003-11-05 03:51:12 anonymous2 [Reply | View]
Interesting thread on the possible future(s) of WebObjects:
http://www.omnigroup.com/mailman/archive/webobjects-talk/2003-November/date.html
-
Oh, my...
2003-11-05 02:43:30 anonymous2 [Reply | View]
A second article related to WebObjects in a row!
Good work :)
For your entertainment:
"Anything new on the Horizon of Webobjects"
http://lists.apple.com/mhonarc/webobjects-dev/msg04344.html







I had to try it out to find out.
Other than that this article ROCKS! it's very clear and is way better some other WO litterature out there. thanks Josh... :) We want more. How about a book about how to learn Java using WO.