validateAction

This method is called to give your component the chance to verify that it has the inputs and resources that it needs to complete successfully. If you return 'false' from this method execution of the action sequence will terminate.

This method should only be used to check that the inputs are available; it should not check the values of inputs because they are not guaranteed to be available at this point during execution. If your component needs resources such as a template file referred to in the action sequence as "new-employee-greeting", you can check that the resource is available by calling isDefinedResource() with "new-employee-greeting" as the argument.

If your component needs an input called 'employee-id', you can check that it has been defined in the action sequence by calling isDefinedInput() with "employee-id" as the argument.

If your component needs an output called "employee-greeting-email-text", you can check that it has been defined in the action sequence by calling isDefinedOutput() with "employee-greeting-email-text" as the argument.

Your validateAction method would now look like this

public boolean validateAction() {
    if (!isDefinedResource("new-employee-greeting")) {
        error( "A template called 'new-employee-greeting' has not been defined" );
        return false;
    }
    if (!isDefinedInput("employee-id")) {
        error( "An employee id is needed" );
        return false;
    }
    if (!isDefinedOutput("employee-greeting-email-text") ) {
        error("An output called 'employee-greeting-email-text' has not been defined" );
        return false;
    }
    return true;
}

Notice that we are only checking to see if the input has been defined and we are not trying to get the input value.

The validateAction of the EmailComponent looks like this:

public boolean validateAction() {
    // make sure that we can get a 'to' email address
    if (!isDefinedInput("to")) {
        error(Messages.getErrorString("Email.ERROR_0001_TO_NOT_DEFINED",
              getActionName()));
        return false;
    }
    // make sure that we can get a subject for the email
    if (!isDefinedInput("subject")) {
        error(Messages.getErrorString("Email.ERROR_0002_SUBJECT_NOT_DEFINED",
              getActionName()));
        return false;
    }
    // make sure that we have either a plain text or html message for the email
    if (!isDefinedInput("message-plain") && !isDefinedInput("message-html")) {
        error(Messages.getErrorString("Email.ERROR_0003_BODY_NOT_DEFINED",
              getActionName()));
        return false;
    }
    return true;
}

Notice that this method does not check for the optional parameters such as 'cc', 'bcc', or email attachments but only checks for the minimum parameters that are required for the component to execute successfully.

You do not have to call for each individual resource, input, or output. If you prefer, you can work with java.util.Set objects that contain the names of the available items. These sets can be obtained by calling getResourceNames(), getInputNames(), and getOutputNames(). For example

Set inputNames = getInputNames();
if( !inputNames.contains( "param1" ) && !inputNames.contains( "param2" ) ) {
    error( "I need both param1 and param2" );
    return false;
}