ConcourseSuite Support

Support
Corporate
PUBLIC PROFILE

Code Action Classes

A module Action Class contains the server-side code that gets executed when the user selects a URL in their browser.

For example, when the user clicks “Generate a Report” the server maps the user request to Java code that prepares the data for displaying back to the user. So, the action might perform database queries, retrieve information from a cache, create Java Beans, etc. When the action is done, all of the data is forwarded to a JSP for returning HTML back to the user's browser.

The Simplest Action Class

The following code is actually quite powerful, although no work is actually being done here. Based on additional ConcourseSuite CRM configuration parameters, the following URL might be enabled...

http://127.0.0.1/crm/Prototype.do?command=Default

This causes the following code to be executed by the server...

package com.concursive.crm.web.modules.prototype.actions;

import com.concursive.commons.web.mvc.actions.ActionContext;
import com.concursive.crm.web.controller.actions.CRMModule;

public final class Prototype extends CRMModule {
public String executeCommandDefault(ActionContext context) {
      return ("DefaultOK");
  }
}

Before any code is executed, the Controller will ensure that the browser has already logged into ConcourseSuite CRM before continuing.

Next, if the CRM configuration has a mapping between Prototype and DefaultOK then the Controller will execute the Default Action of the Prototype Action Class, then based on the return string, forward the response to the mapped action, which might be defined as a JSP or a chained Action.

Important Notes About Action Classes

  1. Action Class methods must be in the form executeCommandName(ActionContext context) where [name] is the name of an action, like Add; when a request is made that does not specify a command, then executeCommandDefault(ActionContext context) is used
  2. Trap all errors, with catch (Exception) in the action's method and return an OK or Error result to the Controller
  3. Always use finally to release any resources used by the action, like a database connection, whether the method was successful or not
  4. Use a single database connection sparingly and quickly, be sure to free the connection when finished; getConnection(context) retrieves a connection for the current user from the pool, and freeConnection(context, db) returns it back to the pool; Do not use connection.close() or it will really be closed
  5. Store objects in the request to be used by JSPs; use session objects sparingly as they require additional memory storage
  6. When a POST is finished, use a redirect 302 instead of displaying the page within the POST request.

Extending com.concursive.crm.web.controller.actions.CRMModule

Extending the CRMModule class provides many useful methods that can be used during the action code execution.

Important Methods

  • hasPermission() -- to verify user permissions
  • getConnection(), freeConnection(), renewConnection() -- to retrieve and reuse database connections
  • getUserId() -- to get the logged in user's id
  • getUserRange() -- to get the user ids of the logged in user and the ids of those in that user's hierarchy as CSV
  • getUserSiteId() -- to get the logged in user's site id, or -1 if none
  • getUser() -- to get the logged in user's User session
  • getPagedListInfo() -- to get the specified pagedListInfo object for a specific record list view
  • getUserTimeZone() -- to get the logged in user's time zone
  • hasAuthority() -- to verify access to a record
  • validateObject() -- to validate a CRM object
  • processInsertHook(), processUpdateHook(), and processDeleteHook() -- to activate the workflow engine
  • addRecentItem(), deleteRecentItem(), getRecentItem() -- to work with the "recent items" list
  • getSystemStatus() -- to retrieve the system preferences that this user belongs to
  • getPath(), getDbNamePath(), getDatePath(), getWebInfPath -- returns a path to the file library
  • isRecordAccessPermitted(context, db, int) , isRecordAccessPermitted(ActionContext, Object) -- Check record permissions for the user on an object
  • isPortalUser() -- returns whether the current user is using the portal interface or not
  • indexAddItem(), indexDeleteItem() -- to add or remove objects from the search index
  • executeJob() -- to force execution of scheduled or unscheduled jobs
  • getViewpointInfo() -- to get details about the user's current viewpoint

Debugging

ConcourseSuite CRM has been configured to use Apache Commons Logging.

If the web application was installed with debugging turned on, then debug output will be sent to a log file in $/logs/; on Linux, Mac, and Sun the file is catalina.out and on Windows the files are stdout.txt and stderror.txt.

In any class the following code convention is used to output debug info:

LOG.debug("Some text");

Code with System.out messages will not be accepted. System.out messages can slow down a production web server when enabled and use a lot of disk space.

Sign in to add your comment.