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
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 29 of 29.
-
Direct to Web java.lang.ClassNotFoundException: Application error
2004-12-30 12:42:33 Florijan [Reply | View]
-
Direct to Web java.lang.ClassNotFoundException: Application error
2004-12-30 14:17:43 Josh Paul |
[Reply | View]
Florijan,
There are a few things that come to mind:
1) check to see you are building the correct target. You will find this setting in the upper left corner of your project window, as a popup menu. It should be set to "D2WTutorial9".
2) check to see that the Application class is a part of your Application Server build target. You can check this by selecting Application Server from the Target popup menu (as above). Then check to see that the checkbox to the left is checked. If you don't see a checkbox, select View->Groups & Files Columns->Target Membership.
3) make sure there are no spaces in the path to your project. For example: "/Users/Florijan/Projects/D2WTutorial9" works well, whereas "/Users/Florijan/My Projects/D2WTutorial" does not.
HTH,
Josh -
Direct to Web java.lang.ClassNotFoundException: Application error
2004-12-31 05:43:22 Florijan [Reply | View]
Thank you Josh,
Creating projects in paths with no spaces helped. I managed to run the login screen of WebObjects. However, when I clicked login, I got the following error:
Application:
D2WTutorial
Error:
com.webobjects.foundation.NSKeyValueCoding$UnknownKeyException: [ valueForKey()]: lookup of unknown key: 'visibleEntityNames'. This WOComponent does not have an instance variable of the name visibleEntityNames or _visibleEntityNames, nor a method of the name visibleEntityNames, _visibleEntityNames, getVisibleEntityNames, or _getVisibleEntityNames
Reason:
[<com.webobjects.appserver.WOComponent name: MenuHeader subcomponents: null > valueForKey()]: lookup of unknown key: 'visibleEntityNames'. This WOComponent does not have an instance variable of the name visibleEntityNames or _visibleEntityNames, nor a method of the name visibleEntityNames, _visibleEntityNames, getVisibleEntityNames, or _getVisibleEntityNames
From what I can make out of it, it looks like he can not access methods of the classes generated by the EO model. And I am using the RealEstate tutorial model specified in the D2W documentation. I really don't understand why that happens because the model is freshly installed with the system, and the OpenBase says that he is runnig the database.
I would be grateful for suggestions on how to overcome this.
Thank you
-
problem fixed
2004-12-31 06:13:25 Florijan [Reply | View]
Managed to fix my problem. I went through the XCode 1.5 documentation and saw that they had an issue with generating D2W projects, by not placing two java classes in their proper place. After changing that in my projects I now can get what the tutorial says i should get. Maybe now i can continue learning...
Thanks for your assistance,
'
Regards,
F -
problem fixed
2006-12-09 23:32:02 dbsurf [Reply | View]
I would like to know in details, what you did to overcome this issue. I have the same problem with my D2W application and all the samples. I appreciate any help!
Error: com.webobjects.foundation.NSKeyValueCoding$UnknownKeyException: [ valueForKey()]: lookup of unknown key: 'visibleEntityNames'. This WOComponent does not have an instance variable of the name visibleEntityNames or _visibleEntityNames, nor a method of the name visibleEntityNames, _visibleEntityNames, getVisibleEntityNames, or _getVisibleEntityNames
Reason: [<com.webobjects.appserver.WOComponent name: MenuHeader subcomponents: null > valueForKey()]: lookup of unknown key: 'visibleEntityNames'. This WOComponent does not have an instance variable of the name visibleEntityNames or _visibleEntityNames, nor a method of the name visibleEntityNames, _visibleEntityNames, getVisibleEntityNames, or _getVisibleEntityNames -
problem fixed
2006-12-10 08:55:41 Josh Paul |
[Reply | View]
From the release notes:
For Direct To Web projects: When creating a new Direct To Web project, you'll notice that the MenuHeader.java and PageWrapper.java source files are not correctly added to the Application Servers target and are in the Bundle Resources build phase and not in the Sources build phase. After creating a new project, open the Application Servers target in the Groups & Files view and drag the MenuHeader.java and PageWrapper.java source files from the Bundle Resources build phase to Sources build phase.
Instructions, as explained by Andres Toussaint on the Apple WebObjects list:
'After you create your D2W project in xCode, open the contents of the "Targets" group (a red bullseye).
Double click the "Application Server" target.
Select "Build Phases". In the right hand you will see the build phases, indicated by "Sources", "Bundle resources", etc..
Drag the MenuHeader.java and PageWrapper.java from the Bundle Resources to the Sources.
That is all.'
HTH. -
problem fixed
2006-12-10 08:55:17 Josh Paul |
[Reply | View]
From the release notes:
For Direct To Web projects: When creating a new Direct To Web project, you'll notice that the MenuHeader.java and PageWrapper.java source files are not correctly added to the Application Servers target and are in the Bundle Resources build phase and not in the Sources build phase. After creating a new project, open the Application Servers target in the Groups & Files view and drag the MenuHeader.java and PageWrapper.java source files from the Bundle Resources build phase to Sources build phase.
Instructions, as explained by Andres Toussaint on the Apple WebObjects list:
'After you create your D2W project in xCode, open the contents of the "Targets" group (a red bullseye).
Double click the "Application Server" target.
Select "Build Phases". In the right hand you will see the build phases, indicated by "Sources", "Bundle resources", etc..
Drag the MenuHeader.java and PageWrapper.java from the Bundle Resources to the Sources.
That is all.'
HTH.
-
MySQL
2003-10-09 12:51:50 anonymous2 [Reply | View]
can you provide a detail explanation of the connection properties in regards to MySQL - in particualr how to connect to a local MySQL server and a remote MySQL server.
I have not been able to find this anywhere.
Thanks -
MySQL
2003-10-09 13:46:45 Josh Paul |
[Reply | View]
Yup...MySQL. I initially had a tough time setting it up as well. Before I dive in here, I highly recommend OpenBase database products.
In order to set up MySQL you will need to install it first. If you have not, I recommend using Aaron Faby's fantastic installer (http://www.serverlogistics.com). After installing MySQL you will need the correct JDBC driver, which can be downloaded from the MySQL website.
From there, you will need to do the following, using the "Model:Switch Adaptor..." menu item:
1) make sure your EOModel is using the JDBC connector
2) enter the Username for the database you are connecting to
3) enter the Password for the user/database you are connecting to
4) enter the URL for your database (i.e. jdbc:mysql://localhost/my_database)
5) enter the JDBC driver information (i.e. org.gjt.mm.mysql.Driver)
I hope that information helps. -
MySQL
2003-10-15 06:58:06 anonymous2 [Reply | View]
What is the main reasoning for Openbase versus MySQL. I opened minded as to both - just wondering why you recommend it?
Thanks
PS - Instructions 4&5 are the two I did not have a clue how to input thanks. -
MySQL
2003-10-15 08:50:31 Josh Paul |
[Reply | View]
(My personal opinion...)
I've used a variety of databases, including MySQL and OpenBase. I've found OpenBase's support to be exceptional, as well as the administration tools. The company also uses WebObjects for it's online presence, so they know how both WO and OB interact in "real world" scenarios.
I within the past two years, I have moved a WO project from OpenBase to MySQL and back again. I've found the performance of both to be similar (~50,000 transactions per day). I moved back to OB for two reasons:
1) I prefer the OB administration tools
2) OB offers an option to index Word, PDF, etc.
The beauty of EOF is that I can move my project(s) from one database to another with little effort.
-
WebObjects Book(s), Please!
2003-10-07 09:20:16 anonymous2 [Reply | View]
Dear O'Reilly Network,
Please, please, please write a series of books on WebObjects! The writer of this article would make a great author!
Thanks!
-
Thanks!!!
2003-10-05 13:16:55 anonymous2 [Reply | View]
Thank you O'Reilly for the article. I hope this is the first in a very long series of articles. Please consider a series of books on WO!!
-
Please.. books! and support from Apple
2003-10-05 04:42:02 thajeztah [Reply | View]
I would be very pleased to see O'Reilly have a book on WebObjects. I'm allways on the look to find good books on WebObjects (even had to travel to London from the Netherlands to find one!)
However, so far I haven't find a book that had the same quality as any O'Reilly release.
I think WebObjects could have GREAT potential, -if-:
1) Apple would promote it more (I almost seems they forgot it existed)
2) Good book and articles would appear
3) A 'developer' version would be included on the Developers tools - CD that is included with OS X!
-
Yes, but...
2003-10-01 23:23:40 anonymous2 [Reply | View]
A lot of those "gotcha's" have been addressed in 5.2 and a lot of them are pretty questionable. For example, many of them are along the lines of "why x, when java already has y?" Well, if you don't like x just use y.
Thanks O'Reilly for shedding a little light on what I think is the best web application development toolkit available!
-
We want more....
2003-09-30 11:02:45 anonymous2 [Reply | View]
Articles on Web Objects that is. I'm currently learning Java for the sole purpose of becoming a Web Objects developer. Books and articles on WO are few and far between. The more I read about WO the more interested I become. I love how absolutely everything seems to follow along with the OOP structure. Simply exciting.
RE
-
More, please!
2003-09-29 00:17:51 cmittendorf [Reply | View]
WebObjects is really a nice tool for creating apps on the web. But it lacks promotion and publicity! Therefore, please O'Reilly, I would love to see more articles on this subject!
-
WebObjects tutorial
2003-09-28 17:06:12 anonymous2 [Reply | View]
Does the WO writer have a book? This exceptional teaching on a very big (I never could get my thoughts around the whole thing), rich development environment.
Thanks,
Jim Reinhart
jreinhart1@cox.net
-
How about a book O'Reilly?
2003-09-27 16:33:57 anonymous2 [Reply | View]
Given O'Reilly's strong support for all things Mac OS X related, I'm very surprised they haven't published a book on WebObjects.
I'm sure there are others who would welcome a definitive guide too.
Could anyone comment on whether such a book is in the works?
-
http://www.codon4.com
2003-09-27 08:03:33 anonymous2 [Reply | View]
eh, this was on http://www.codon4.com like a year ago
-
More WO stuff on MacDevCenter please.
2003-09-27 07:36:50 anonymous2 [Reply | View]
It is really good to see an article about WebObjects finally made it to MacDevCenter. I hope this is just the beginning of more WebObjects articles to come; maybe one day there will be a special section on WebObjects like the Cocoa Programming section.
-
Open Source Alternative?
2003-09-27 07:16:37 anonymous2 [Reply | View]
Perhaps an open source alternative to WOF+EOF is Tapestry + Cayenne... something to consider in any case... -
Open Source Alternative?
2003-09-28 20:46:39 anonymous2 [Reply | View]
Using WO is plan fun.....really.
The way the database logic and the application server just wrap together nicely, using WO is actually quite a joy compared to Tomcat or JBoss with all the same power.... -
Open Source Alternative?
2003-09-29 07:41:37 anonymous2 [Reply | View]
> Using WO is plan fun..... really.
Yep. Too much fun sometime...
Tapestry is conceptually based on the same principle as WOF. Ditto for Cayenne as an alternative to EOF. So there is a clear and viable open source alternative to WebObjects.
Lastly, Cayenne and Tapestry don't have anything to do with the Exxon Valdez (aka J2EE).
-
Yes, but...
2003-09-27 02:51:17 anonymous2 [Reply | View]
WOF and specially EOF are very fine piece of machinery indeed.
But... there are several gotcha you need to keep firmly in mind if you are using the Java incarnation:
http://www.omnigroup.com/mailman/archive/webobjects-dev/2002-March/020441.html
In any case, congratulation for writing what's perhaps the first "mainstream" article about WebObjects...






When i try making a Direct to Web project in XCode, and I go through the tutorial for it, i get a succesful compilation result, but when the projects starts running i don't get further from the command line. It loads it's WebObjects extensions, and then reposrts the following:
Can't load Application class, exiting...
java.lang.ClassNotFoundException: Application
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at com.webobjects._bootstrap.WOBootstrap.main(WOBootstrap.java:68)
Executable D2WTutorial9 has exited with status 1.
i tried running it on a newly installed system, and on a newly made user, i can never get it to work. The funny thing is that the guy next to me can run those same tutorials, and also the project that i made and transferred to him.
Any help would be appreciated because i really don't know where this is coming from.
Thanks