Set an image for ConcourseSuite Community Edition

Sign In or Register

ConcourseSuite Community Edition

Core Team
PostgreSQL Java
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 Centric CRM configuration parameters, the following URL might be enabled...

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

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

package org.aspcfs.modules.prototype.actions;

import com.darkhorseventures.framework.actions.ActionContext;
import org.aspcfs.modules.actions.CFSModule;

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

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

Next, if the Centric 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

Extending org.aspcfs.modules.CFSModule

Extending the CFSModule 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 Centric 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

Centric CRM does not use any prominent logging facilities.

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:

if (System.getProperty(“DEBUG”) != null) {
 System.out.println(“Class Name-> Some text”);
}

Code with System.out messages will not be accepted unless the DEBUG condition is used. System.out messages can slow down a production web server when enabled and use of disk space.

Sign in to add your comment.