WebObjects 4: Changing the default page in a WebObjects application

This article describes how to change the default page of a WebObjects application from the page defined by Main.wo to the page or WOComponent of your choice.
This article has been archived and is no longer updated by Apple.

By default, a WebObjects app opens to a page named "Main". Any reference to "Main" in a hyperlink, action method, or dynamic element directs users to this page named "Main". Sometimes WebObjects developers wish to change this "default" page to a different WOComponent.

You can change this default page by overriding a method in your WOApplication subclass. In Objective C, the method is:

- (WOComponent*)pageWithName:(NSString*)aName inContext:(WOContext *)aContext

In Java, the method is:

public WOComponent pageWithName(java.lang.String pageName, com.apple.yellow.webobjects.WOContext context).

The source code examples below demonstrate how to implement the change. Please note that if you override pageWithName:inContext: in this way, all references to "Main" in your application will now be references to "DiffDefPage". Users are no longer able to access the Main.wo component.

Example: Objective C

In Objective-C, add the following code to your Application.m file:

- (WOComponent *)pageWithName:(NSString *)pageName inContext:(WOContext *)context  
// redirect any requests for the Main to DiffDefPage
if (!pageName || [pageName isEqualToString:@"Main"])
return [super pageWithName:@"DiffDefPage" inContext:context];
return [super pageWithName:pageName inContext:context];

Example: Java

In Java, add the following code to your Application.java file:

public WOComponent pageWithName(String pageName, WOContext context)
// redirect any requests for the Main to DiffDefPage
if ((pageName == null) || (pageName.equals("Main")))
return super.pageWithName("DiffDefPage", context);
return super.pageWithName(pageName, context);

Last Modified: Feb 18, 2012

Additional Product Support Information