Child pages
  • Your First Rest Project

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: replaced left > right

...

Now, it's time to link the two entities together. A Author can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on Author and select New Relationship. On your right, select BlogEntry in the list. On your left, select to many BlogEntries, and on your leftright, select to one Author. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure and a new foreign key named is checked (it is checked by default). The Create Relationship pane should look like this:

...

That component code will loop over the blog entries and display the title of the entry + the name of the author. Save everything and run the application.

If you go to http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.htmlImage Removed, you will see the list of blog entries!

...

We need to add other methods to receive the BlogEntry object from the controller. In BlogEntryShowPage.java, add:

Code Block

  
 private BlogEntry blogEntry;
   

    @ERXRouteParameter
    public void setBlogEntry(BlogEntry blogEntryFromController) {
      this.blogEntry = blogEntryFromController;
    }
   

    public BlogEntry blogEntry() {
      return this.blogEntry;
    }

...

The Java part of the work is done, so save the Java class. It's time to work on the component part. Open BlogEntryShowPage.wo and between the <body></body> part, add:

Code Block


   <h1><wo:str value="$blogEntry.title" /></h1>
    <p><wo:str value="$blogEntry.content" /></p>
    <p>Created on: <wo:str value="$blogEntry.creationDate" dateformat="%Y/%m/%d" /></p>
    <p>Added by: <wo:str value="$blogEntry.author.fullName" /></p>

...

Save the component and run the app. Go to http://192.168.0.102:52406/cgi-bin/WebObjects/BlogRest.woa/ra/blogEntries.htmlImage Removed to get the list of posts, and you should see a link on the title. Click on it, and now you get the full details of the blog entry!

...