Using WebObjects "Direct to Web" Technology
Pages: 1, 2
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...
user.d2wmodel is a collection of
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.)
user.d2wmodelfile. I'm going to help you dissect one of them:
Rule can be read as follows:
If the current
task(i.e. action) is "Edit" and the current
Entity's (i.e. table) name is "User"
passwordattributes (i.e. columns) on the current page.
In other words, when someone wants to "Edit" a User, give them
access to the
So, what about this whole
Priority business? In order to
demonstrate it, go ahead and
copy the highlighted
paste it. Then select the newly created
You should change the Right-Hand Side's Value from
You will also want to change the
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
Go ahead, just try it!
You should leave your web browser open, since your going to be going back to it very shortly.
user.d2wmodel again and change the priority of
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
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
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
I simply performed a
username attribute. I then renamed both the
Column information to reflect my new criteria. I also
decided to allow
NULL values by checking the option under
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
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
in the left most browser (aka the
key path browser).
Follow your intuition and select the
and click on the GreenArrow:Right
button. You should then find the
nameFirst listed below
password attributes. When
you click on the "Save" button in the Assistant window, your
web browser should reload with your changes.
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
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
Note for MySQL users
2004-03-04 15:29:12 binouch [View]
2003-11-12 12:27:49 [View]
2003-11-09 21:26:50 anonymous2 [View]
2003-11-05 03:51:12 anonymous2 [View]
2003-11-05 02:43:30 anonymous2 [View]