Previous | Next
WireHose Developers Guide

Customizing how items are shown

Since WireHose is an object-oriented system, with a strong emphasis on code reuse, there is a clean separation between business logic and presentation components. For maximum flexibility, WireHose allows you to use any component to render or edit an object on a page. Special components called "switchers" keep WireHose updated as to which object is currently being rendered or edited.

  1. Select the Web Components group in the Files pane.
  2. Choose New File... from the File menu. Scroll down to the WireHose Resource Renderer template and click Next.
  3. Name it ShowRSSItem, add it to the Application Server target in the Hello World project, and click Finish.
  4. Add this method to ShowRSSItem.java:
    public RSSItem item() {
        return (RSSItem)object();
    }

    Note: This method isn't strictly required; it's a convenience so that WebObjects Builder will display the bindings available for RSSItem objects. You can bind values such as the item's name to either object.name or item.name.

  5. Open ShowRSSItem.wo in WebObjects Builder.

  6. Delete the paragraph and insert a new one. Inside it, insert a WOHyperlink, and bind its href to item.link

  7. Inside the link, insert a WOString. Bind its value to item.name
  8. Insert a couple dashes, and another WOString. Bind its value to item.textDescription

    Note: Since "title" is an optional attribute in an RSS item, you may want to use WOConditional components to render the link differently depending on whether or not the item has a name.

Since it's traditional in an aggregator to indicate where an item originated, you can add a link to the item's feed. This link will use the WireHose "Display" direct action, which acts as a cover for the WHShowObjectPage component. The Display direct action takes one parameter, "resource", set to the global ID of the object to be displayed. WHEnterpriseObject provides utility methods to encode and decode globalIDs as compact strings suitable for this purpose.

  1. Add this method to RSSItem.java:
    public String feedGlobalID() {
        return WHEnterpriseObject.encodedGlobalIDForObject(feed());
    }
  2. In WebObjects Builder, after the description, insert a pair of parentheses, and between them, insert a WOHyperlink. Bind its actionClass to "Display", and add a binding called ?resource set to item.feedGlobalID.

  3. Inside the WOHyperlink, add a WOString with its value set to item.feed.name

The final step is to modify the layout dictionary to tell the WHSwitchRenderer components to use ShowRSSItem instead of WHShowResource.

  1. Select layoutDict.plist in the Resources group in Project Builder.
  2. Find this section:
    renderers = {
        WHChannel = WHShowChannel;
        WHComponentChannel = WHShowComponentChannel;
        WHFetcher = WHShowFetcher;
        WHResource = WHShowResource;
    };
       
  3. Change it so it reads:
    renderers = {
        WHChannel = WHShowChannel;
        WHComponentChannel = WHShowComponentChannel;
        WHFetcher = WHShowFetcher;
        WHResource = WHShowResource;
        RSSItem = ShowRSSItem; 
    };
       
  4. Build and launch the application, and open this URL in your browser:
    http://127.0.0.1:2020/cgi-bin/WebObjects/HelloWorld.woa/wa/Drill

    You'll see your new component is being used to display items.

Note: Since there is a to-many relationship between RSSFeed and RSSItem, you could build a ShowRSSFeed component, and include an option to show the individual items for a feed.

To do this, you would embed a WHSwitchRenderer component inside a WORepetition which iterates over the feed's items, and set the switcher's object binding to the item. WireHose will automatically include the proper renderer component to show an item.

At this point the business logic for Hello World is complete. RSS feeds and items are modeled and being imported into the database. The next step will be to customize Hello World's user interface so users can search items, login and create personalized topics for their page.


Previous | Next