Now that our data model is in a framework and that we have a basic REST application working, we are going to build a DirectToWeb application to manage the blog system. But first, what is DirectToWeb (D2W)? D2W is a rules-based application model where you can change the behavior of the application by rules. D2W is perfect for "admin" apps, for applications that share a common model or for "CRUD" (Create Read Update Destroy) applications.
Name it D2WBlog. The next step is to link the BlogCommon framework to the D2W app. To do so, right-click on D2WBlog and select Build Path -> Configure Build Path.
Just click the Login button and you will get into the application. Navigate in the application, but you will see that it don't do anything special and you don't see data. You can terminate the app (by clicking the red stop button in Eclipse's console).
The loginAction logic is quite simple: we check the value from the form, we check in the data source if the email address exists, if that's the case we store it in the session and we redirect the user to the default (navController().homeAction()) page, if now the user stays on the Main page.
We are done with the login logic, so we can move to the next step: working on the navigation. The navigation is quite simple: we want two tabs, Posts and Authors, when one of the two tabs is selected, we display the list of objects for the selected tabs, and we have two links: one to create a new blog entry or a new author, and the other to query (search) for matching objects.
The navigation structure is done in a "plist" file. If you are a Mac OS X guy, you probably know what is a plist, but if not, a plist is like a JSON structure to hold key/values. The plist file is located in the Resources folder, the file's name is NavigationMenu.plist. By default, Eclipse will open the file in Xcode, which might not be what we want. To open it in a text editor in Eclipse, right-click on NavigationMenu.plist and select Open With -> Text Editor.
Add the following method in the Session class for the navigation root.
The first array in the plist defines what the top level navigation is going to be, and this is where we define the two tabs (the childrenChoice dictionary). After that, we define the other parts of the navigation. You see references to action = session.navController. This is the action (method) that will be called for the specified navigation element, so let's create those methods in the MainNavigationController class.
The first method we will implement in MainNavigationController is a generic method to list objects for a specific entity.
The controller already have methods to query objects (queryPageForEntityName) and create new ones (newObjectForEntityName), so the next step is to create the methods for our two entities.
We also need to change the homeAction method so that when an user log ins, he see the list of blog entries.
Save the file and run the app.
After login, you will see the blog entries and if you click the Authors tab, you see the list of authors. Each item in the list has 3 actions by default: Inspect (view the object), Edit (modify the object) and the red X button to delete the object.
Click Edit on an author, and you will see that it displays not only the author's details but also blog entries created for that user. You can even create a new blog entry directly from the author.
Now, edit a blog entry. If you click on the field next to the Creation Date or Last Modified, a calendar widget appears because those two fields are marked as dates in the data model, that's EOF and D2W magic at work.
Those two customizations can be done by adding D2W rules. The D2W rules are in two files, located in the Resources folder, d2w.d2wmodel and user.d2wmodel. To edit the files, make sure you installed RulesModeler, a Mac application that manages D2W rule files. If RuleModeler is present, you can simply double-click on d2w.d2wmodel and the file will open in RulesModeler.
We are done. Save the file in RulesModeler, and run the application again. Try editing a blog entry and you will notice that we know have a rich editor for the content and that the ordering of the fields is different, without having to change the HTML or the Java code!
Congratulations, you are done with the D2W tutorial! The next tutorial is about creating a stateful application.
I have no hair, but I am pulling it out non the less! I have known about WOnder and WO for a while. My company is building a web app server (We want to use Rest and Sencha JS libs for mobile devices) and I am trying to persuade my developers to look at WO. However - I (granted I am the worst dev on the planet) cannot get past a D2W screen with Home, Tab1 and Tab2. I have no idea where to start - as the docs and videos from WOWODC does not show very well where Eclipse one is to add NewPagegenerated from the d2wFactory.
I can really see the power in the tools, but am really worried given the steep learning curve. Any ideas?
You should ask in the mailing list (webobjectsp-dev@lists.apple.com) because I don't think many people will see your question here.