More on Misusing Dynamic Binding

Brad Cox: Misusing Dynamic Binding When Static Binding Would Do, Part 1

"In this example, the JSP page hard wires a dynamically bound link to the target page in its <a href> command rather than calling a statically bound, type-checkable method of the target page. None of the Web app environments I've seen support the latter option. Pages reference other pages by filename, not as objects, because browsers use HTML, which does it this way."

A while ago Brad Cox was asking questions about WO on the lists. Either he wrote the article above before learning about WebObjects, or he didn't dig very deep... with WebObjects, pages reference other pages as objects, not by filename! It's great!

With WebObjects, hyperlinks and submit buttons typically target the CURRENT page, and are bound (dynamically, mind you, in a declarations file that belongs to the view of the component) to action methods on that (current) page's object instance. The action methods return a new page instance (the page to be shown to the user).

The action method can configure the target page between instanciating it and returning it. ie: nextPage.setSelectedObject(objectChosen()); This is a very cool way to program web apps, because it means you can pass things between pages UNDER THE COVERS, instead of... er, over the covers, ie: in HTTP=URL&Param=eters.

Here's an example action method in a WO page (pages are WOComponents, and the java code of a WOComponent is the controller in the MVC triad):

public WOComponent showDetails() {
    DetailPage nextPage = (DetailPage)pageWithName("DetailPage");
    nextPage.setObjectToShow(selectedObject());
    // maybe you want to tell the next page where it came from
    nextPage.setPreviousPage(this);
    return nextPage;
}

BTW, showDetails, setObjectToShow, selectedObject and setPreviousPage are all method names I made up. pageWithName(String) is authentic.

Written on December 2, 2001