Version 4.10.0

hirondelle.web4j.action
Enum Operation

Object
  extended by Enum<Operation>
      extended by hirondelle.web4j.action.Operation
All Implemented Interfaces:
Serializable, Comparable<Operation>

public enum Operation
extends Enum<Operation>

Type-safe enumeration for common operations.

This type-safe enumeration is somewhat unusual, since its elements are not meant to form a strictly distinct set. For example, one might choose to identify the same operation using either Save or Add, simply according to taste. Elements may be used as desired, but please note that isDatastoreEdit() and hasSideEffects() return true only for specified items.

Many Action implementations can benefit from using a request parameter named 'Operation', whose value corresponds to a specific subset of the members of this enumeration. For example, ActionTemplateSearch expects only Show and Search operations. See ActionImpl.getOperation() as well.

Occasionally, you may need to define just such a subset of operations for your own actions. Typically, your code would use the following code snippets.

Define an Operation RequestParameter in the Action using :

  public static final RequestParameter SUPPORTED_OP = RequestParameter.withRegexCheck(
    "Operation", 
    Pattern.compile("(" + Operation.Show + "|" + Operation.Search +  ")") 
  );
  
Set the value of a corresponding Operation field in the Action constructor using :
  fOperation = Operation.valueOf(aRequestParser.toString(SUPPORTED_OP));
  

Your Action.execute() method will then branch according to the value of the fOperation field.

Note regarding forms submitted by hitting the Enter key.
One must exercise care for the possible submission of forms by hitting the Enter key. Browser behavior is not specified exactly by HTML 4, and various browsers exhibit different behaviors. A common workaround is to place the Operation in a HIDDEN form item, to ensure that it is always submitted, regardless of the submission mechanism.

See as well this discussion of Submit buttons in multilingual applications.


Enum Constant Summary
Activate
          Activate an item.
Add
          Add an item to the datastore.
Apply
          Apply an edit to the datastore.
Change
          Post a change to an item to the datastore.
Delete
          Delete an item from the datastore.
DeleteAll
          Delete all items from the datastore.
Display
          Display a result.
Do
          Generic operation meant as a catch-all.
Fetch
          Retrieve a single item, for read-only display.
FetchForAdd
          Fetch items needed before adding a new item.
FetchForChange
          Fetch a single item, in preparation for editing the item.
First
          Fetch the first item in a list.
Generate
          Generate a result.
Inactivate
          Inactivate an item.
Last
          Fetch the last item in a list.
List
          Retrieve what is usually a list of many items, for read-only display.
ListForChange
          Retrieve what is usually a list of many items, in preparation for editing the items.
Next
          Fetch the next item in a list.
Previous
          Fetch the previous item in a list.
Render
          Render a result.
Save
          Save an edit to the datastore.
Search
          Search for one or more items.
Show
          Show an item.
Start
          Start some process.
Stop
          Stop some process.
 
Method Summary
 boolean hasSideEffects()
          Returns true only if this Operation isDataStoreEdit(), or is Start or Stop.
 boolean isDatastoreEdit()
          Return true only if this Operation represents an action which has edited the datastore : Add, Change, Delete, DeleteAll, Save, Apply, Inactivate, or Activate.
static Operation valueFor(String aOperation)
          Parse a parameter value into an Operation (not case-sensitive).
static Operation valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Operation[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

Add

public static final Operation Add
Add an item to the datastore.


Change

public static final Operation Change
Post a change to an item to the datastore.


Delete

public static final Operation Delete
Delete an item from the datastore.


DeleteAll

public static final Operation DeleteAll
Delete all items from the datastore.


Save

public static final Operation Save
Save an edit to the datastore.


Apply

public static final Operation Apply
Apply an edit to the datastore.


Activate

public static final Operation Activate
Activate an item.

The reverse of Inactivate


Inactivate

public static final Operation Inactivate
Inactivate an item.

Often used to implement an abstract delete operation, where an item is nominally removed (perhaps by setting the value of a certain column), but no physical deletion of records occurs.


Start

public static final Operation Start
Start some process.

The reverse of Stop.


Stop

public static final Operation Stop
Stop some process.

The reverse of Start.


Fetch

public static final Operation Fetch
Retrieve a single item, for read-only display.


FetchForChange

public static final Operation FetchForChange
Fetch a single item, in preparation for editing the item.


FetchForAdd

public static final Operation FetchForAdd
Fetch items needed before adding a new item. An example use case is adding a new item which has a parent of some sort. The parent will need to be fetched before showing the form for adding the child.


List

public static final Operation List
Retrieve what is usually a list of many items, for read-only display.


ListForChange

public static final Operation ListForChange
Retrieve what is usually a list of many items, in preparation for editing the items.


Show

public static final Operation Show
Show an item.


Generate

public static final Operation Generate
Generate a result.


Render

public static final Operation Render
Render a result.


Display

public static final Operation Display
Display a result.


Search

public static final Operation Search
Search for one or more items.


Next

public static final Operation Next
Fetch the next item in a list.


Previous

public static final Operation Previous
Fetch the previous item in a list.


First

public static final Operation First
Fetch the first item in a list.


Last

public static final Operation Last
Fetch the last item in a list.


Do

public static final Operation Do
Generic operation meant as a catch-all.

Method Detail

values

public static Operation[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Operation c : Operation.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Operation valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

isDatastoreEdit

public boolean isDatastoreEdit()
Return true only if this Operation represents an action which has edited the datastore : Add, Change, Delete, DeleteAll, Save, Apply, Inactivate, or Activate.

Intended to identify actions which very likely require a redirect instead of a forward.


hasSideEffects

public boolean hasSideEffects()
Returns true only if this Operation isDataStoreEdit(), or is Start or Stop.

Intended to identify cases that need a POST request.


valueFor

public static Operation valueFor(String aOperation)
Parse a parameter value into an Operation (not case-sensitive).

Similar to valueOf(java.lang.String), but not case-sensitive, and has alternate behavior when a problem is found. If aOperation has no content, or has an unknown value, then a message is logged at SEVERE level, and null is returned.


Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.