Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The first method we will implement in MainNavigationController is a generic method to list objects for a specific entity.

Code Block
languagejava
  public WOComponent listPageForEntityName(String entityName) {
    ListPageInterface listPage = D2W.factory().listPageForEntityNamed(entityName, session());
    EODataSource dataSource = new EODatabaseDataSource(session().defaultEditingContext(), entityName);
    listPage.setDataSource(dataSource);
    return (WOComponent) listPage;
  }

The controller already have methods to query objects (queryPageForEntityName) and create new ones (newObjectForEntityName), so the next step is to create the methods for our two entities.

Code Block
languagejava
  public WOComponent listPostsAction() {
    return listPageForEntityName(BlogEntry.ENTITY_NAME);    
  }
  
  public WOComponent listAuthorsAction() {
    return listPageForEntityName(Author.ENTITY_NAME);    
  }
    
  public WOComponent createPostAction() {
    return newObjectForEntityName(BlogEntry.ENTITY_NAME);
  }
  
  public WOComponent createAuthorAction() {
    return newObjectForEntityName(Author.ENTITY_NAME);
  }

  public WOComponent searchAuthorsAction() {
    return queryPageForEntityName(Author.ENTITY_NAME);
  }
  
  public WOComponent searchPostsAction() {
    return queryPageForEntityName(BlogEntry.ENTITY_NAME);
  }

We also need to change the homeAction method so that when an user log ins, he see the list of blog entries.

Code Block
languagejava
  public WOComponent homeAction() {
    return listPageForEntityName(BlogEntry.ENTITY_NAME);
  }

...

Viewing or editing a blog entry can be improve. The two three things we want to customize:

  • to remove the email address of the author when viewing the blog entry
  • to make the Content field to be a text area instead of a input field, and even better: attach TinyMCE to the text area
  • modifying the order of attributes when viewing or editing a blog entry so that the title field is the first field, followed by content, the two dates and the author

Those two customizations can be done by adding D2W rules. The D2W rules are in two files, located in the Resources folder, d2w.d2wmodel and user.d2wmodel. To edit the files, make sure you installed RulesModeler, a Mac application that manages D2W rule files. If RuleModeler is present, you can simply double-click on d2w.d2wmodel and the file will open in RulesModeler.