Building Custom List Controllers

The public methods provided by the controller factory (com.webobjects.eogeneration.EOControllerFactory) allow you to dynamically generate user interfaces for many types of tasks throughout your application. However, it doesn’t provide methods for all types of tasks, such as list controllers. This topic describes how to programmatically create a list controller.

Problem: You want to display a list controller containing the enterprise objects returned by a fetch.

Solution: Programmatically create a list controller.

The following method constructs a list controller by first creating a generic controller, then by asking the controller factory for a list controller based on the generic controller and an entity name, and then by invoking listObjectsWithFetchSpecification to fetch enterprise objects into the list controller.

 
public void listWithEntityName(String entityName, EOFetchSpecification fs) {
    EOControllerFactory f = EOControllerFactory.sharedControllerFactory();
 
    EOController controller = f.controllerWithSpecification(new NSDictionary (new
       Object[] {entityName, EOControllerFactory.ListTask,
        EOControllerFactory.TopLevelWindowQuestion}, new Object[]
        {EOControllerFactory.EntitySpecification, EOControllerFactory.TaskSpecification,
        EOControllerFactory.QuestionSpecification}), true);
 
    if (controller != null) {
        EOListController listController =         (EOListController)f.controllerWithEntityName(controller,
           EOControllerFactory.List.class, entityName);
    listController.listObjectsWithFetchSpecification(fs);
    listController.setEditability(EOEditable.NeverEditable);
    listController.makeVisible();
    }
}